/* Network-Integrated Multimedia Middleware (NMM)
 * http://www.motama.com/nmm.html
 *
 * Copyright (C) 2006-2007
 * Motama GmbH, Saarbruecken, Germany
 * http://www.motama.com
 *
 * This file is part of NMM. 
 * 
 * NMM is free software; you can redistribute it and/or modify it    
 * under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; only version 2 of the License.      
 * 
 * NMM is distributed in the hope that it will be useful, but WITHOUT 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 
 * License for more details.  
 * 
 * You should have received a copy of the GNU General Public License 
 * along with NMM; if not, write to the Free Software Foundation,    
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */

#ifndef NMM_ITVGuideImpl_HPP
#define NMM_ITVGuideImpl_HPP

#include "nmm/nmm_prefix.hpp"

#include "nmm/comm/NMMObject.hpp"
#include "ITVGuide.hpp"

#include "nmm/plugins/video/tv/interfaces/tvguide/ITVGuidePluginImpl.hpp"
#include "nmm/plugins/video/tv/interfaces/tvguide/ITVGuidePeerObjectImpl.hpp"

#include "visibility.hpp"

namespace NMM
{
  /**
   * Interface to access EPG. 
   */

  class DLLEXPORT ITVGuideImpl  : public virtual NMM::NMMObject { 
  public:
    ITVGuideImpl() { addInterface(new ITVGuide(*this)); registerEvents(); };

    virtual ~ITVGuideImpl() {};

  protected:
    /**
     * Adds a channel to the channel-list
     *\param id ID of the channel wich is used to find show of this channel
     *\param name Name of the channel
     */

    virtual Result insertChannel(const string& id = "", const string& name = "") = 0;
    /**
     * Adds a channel to the channel-list
     *\param cd ChannelDescription to be added
     */

    virtual Result insertChannelDescription(const ChannelDescription& cd) = 0;
   /**
     * Adds an Event to the database
     *\param pd PrgoramDescription, containing the inrformation about the event
     */

    virtual Result insertEvent(const ProgramDescription& pd) = 0;
    /**
     * returns the path, where the XML-Files are stored
     *\return Path to XML-Files
     */

    virtual string getDirectory() = 0;
    /**
     * Returns the Channels, for wich informaion is available
     *\return Channel-list
     */

    virtual list<ChannelDescription >  getChannelsList() = 0;
    /**
     * Returns the channel with the given ID
     *\param id ID of the channel
     *\return name of the channel, if available, empty string otherwise
     */

    virtual string getChannelById(const string& id) = 0;
    /**
     *Return the ID of the Channel with the given name
     *\param name name o the channel
     *\return ID of the requested channel, empty string if not found
     */

    virtual string getChannelByName(const string& name) = 0;
    /**
     *Returns the Event with the given starttime, endtime and channel
     *\param start StartTime of the Event
     *\param end EndTime of the Event
     *\param channel channel of the event
     *\return ProgramDescription containg the information about the event
     */

    virtual ProgramDescription getEvent(const LocalTime& start, const LocalTime& end, const ChannelDescription& channel) = 0;
    /**
     *Returns all show on the specified day and channel
     *\param day date of the day
     *\param channel channel
     *\return List of ProgramDescripytions containing the information of the shows
     */

    virtual list<ProgramDescription >  getEventsOnDayOnChannel(const LocalTime& day, const ChannelDescription& channel) = 0;
    /**
     * Returns a List with Events containing the given search-phrase
     *\param phrase Phrase to search for
     *\param peer Interface to the application the it is notified of new events
     *\return Event-Hitlist
     */

    virtual list<ProgramDescription >  search(const ProgramFilter& pf, const ITVGuidePeerObject* peer = NULL) = 0;
    /**
     * returns the current event on the specified channel
     *\param channel channel_ID
     *@return current event in the specified channel
     */

    virtual ProgramDescription getCurrentEventOnChannel(const ChannelDescription& channel) = 0;
    /**
     * returns the next to current event on the specified channel
     *\param channel channel_ID
     *@return next event in the specified channel
     */

    virtual ProgramDescription getFollowingEventOnChannel(const ChannelDescription& channel) = 0;
    /** 
     * returns a list with all categories, stored in the DB
     *@return strin-list with categories
     */

    virtual list<string >  getCategories() = 0;
    /**
     * requests the TVGuide-Plugin-Interface specified in type
     *@return ITVGuideUpdatePlugin* interface of the requested grabber
     *@param type Type of TVGuidePlugin, wich is its plugin-name, eg IXMLTVPlugin
     */

    virtual ITVGuidePlugin* getPluginInterface(const string& type) = 0;
    /**
       clean up the database. specify the amount of days from today wich data should be kept. older data will be erased
    */

    virtual void cleanDatabase(const nmm_int32& days) = 0;


  private:
    void registerEvents();
  };

}

#include "nmm/nmm_suffix.hpp"

#endif
