/****************************************************************************
 * DESCRIPTION:
 *            
 *
 * $Id: autotimer.h,v 1.6 2005/05/21 11:58:10 ralf Exp $
 *
 * Contact:    ranga@teddycats.de
 *
 * Copyright (C) 2005 by Ralf Dotzert
 ****************************************************************************/
 
#ifndef AUTOTIMER_H
#define AUTOTIMER_H
#include <string.h>
#include <vector>
#include <mysql/mysql.h>
#include <vdr/tools.h>
#include "libmysqlwrapped.h"


#define TRUESTR          "y"
#define FALSESTR         "n"
#define FIELDTITLE       "title"
#define FIELDSUBTITLE    "subtitle"
#define FIELDDESCRIPTION "description"


class cXxvAutoTimer : public cListObject
{
private:
       int    _id;
       int    _active;
       int    _done;
       char   _search[101];
       char   _searchFields[101];
       int    _searchTitle;
       int    _searchSubTitle;
       int    _searchDescription;

       int    _nrChannelsToUse;
       std::vector <int> _channels;
       std::string _channelNames;
       std::string _channelStr;


       int    _start;
       int    _stop;
       int    _minlength;
       int    _priority;
       int    _lifetime;
       char   _dir[101];
       int    _useChannel;
       int    _useStart;
       int    _useStop;

       // Parameters used in XXV > 0.20
       int    _vps;
       int    _prevMinutes;
       int    _afterMinutes;

       int    _useWeekDays;
       int    _weekMon;
       int    _weekTue;
       int    _weekWed;
       int    _weekThu;
       int    _weekFri;
       int    _weekSat;
       int    _weekSun;
       char   _weekDays[29];

       //internal buffer
       char  _sql[1000];


       const char *boolToString(int boolVal)     {if(boolVal == 1)  return(TRUESTR); else return(FALSESTR);}
       const char *fieldsToString();

public:
    cXxvAutoTimer();
    ~cXxvAutoTimer();
    void Reset();
    void cXxvAutoTimer::operator= (cXxvAutoTimer &param);
    void SetId(const int& theValue)       {  _id = theValue;}
    int GetId() const                     {   return _id;}

    void SetActive(const char * theValue) {  if(theValue != NULL && strcmp(theValue, FALSESTR)==0)
                                                _active = 0;
                                             else
                                                _active = 1;
                                          }
    void SetActive(const int& theValue)   {  _active = theValue; }
    int GetActive() const                 {   return _active;}
    int *GetActiveRef()                   {  return(&_active);}

    void SetDone(const int& theValue)     {  _done = theValue;}
    void SetDone(const char *theValue)    {
                                            if(theValue != NULL && strcmp(theValue, FALSESTR)==0)
                                                _done = 0;
                                            else
                                                _done = 1;
                                          }
    int GetDone() const                   { return _done; }
    void SetSearch(const char* theValue)  { strncpy(_search,theValue, sizeof(_search)); }
    char *GetSearch()                     { return _search; }

    int  GetSearchLen()                   {return(sizeof(_search));}
    void SetInfields(const char* theValue);

    int  *GetSearchTitleRef()             { return(&_searchTitle);}
    int  *GetSearchSubTitleRef()          { return(&_searchSubTitle);}
    int  *GetSearchDescriptionRef()       { return(&_searchDescription);}

    void SetChannels(const char* theValue);
    int   GetNrOfChannels()               { return(_channels.size());}
    int   GetChannelNumber(int index)     { return _channels[index];}
    int  *GetChannelNumberRef(int index)  { return &(_channels[index]);}

    void  AdjustNrOfChannels()            { return(_channels.resize(_nrChannelsToUse, 1));}
    int GetNrChannlesToUse()              { return _nrChannelsToUse;}
    int *GetNrChannlesToUseRef()           { return &_nrChannelsToUse;}

    const char *GetChannelNames();
    const char  *GetChannelStr();

    int   GetUseChannel()                    { return _useChannel;}
    void  SetUseChannel(const int& theValue) { _useChannel = theValue;}
    int  *GetUseChannelRef()                 { return &_useChannel;}

    void SetStart(const int& theValue);
    int GetStart()                         { return _start; }
    int *GetStartRef()                     { return &_start; }

    int  GetUseStart()                     { return _useStart; }
    int *GetUseStartRef()                  { return &_useStart; }

    void SetStop(const int& theValue);
    int  GetStop()                         { return _stop;  }
    int *GetStopRef()                      { return &_stop;  }
    int  GetUseStop()                      { return _useStop; }
    int *GetUseStopRef()                   { return &_useStop; }

    void SetMinlength(const int& theValue){ _minlength = theValue;}
    int  GetMinlength() const             { return _minlength;}
    int *GetMinlengthRef()                { return &_minlength;}


    void SetPriority(const int& theValue) { _priority = theValue; }
    int  GetPriority() const              { return _priority;  }
    int *GetPriorityRef()                 { return &_priority;  }

    void SetLifetime(const int& theValue) { _lifetime = theValue;}
    int GetLifetime() const               { return _lifetime;  }
    int *GetLifetimeRef()                 { return &_lifetime;  }


    void SetDir(const char* theValue)      { strncpy(_dir, theValue, sizeof(_dir)); }
    char *GetDir()                         { return _dir;  }
    int  GetDirLen()                       { return(sizeof(_dir));}

    void SetVPS(const char *theValue)    {
      if(theValue != NULL && strcmp(theValue, FALSESTR)==0)
        _vps = 0;
      else
        _vps = 1;
    }
    int GetVPS() const                 {   return _vps;}
    int *GetVPSRef()                   {  return(&_vps);}

    void SetPrevMinutes(const int& theValue){ _prevMinutes = theValue;}
    int  GetPrevMinutes() const             { return _prevMinutes;}
    int *GetPrevMinutesRef()                { return &_prevMinutes;}

    void SetAfterMinutes(const int& theValue){ _afterMinutes = theValue;}
    int  GetAfterMinutes() const             { return _afterMinutes;}
    int *GetAfterMinutesRef()                { return &_afterMinutes;}


    int  GetUseWeekDays() const             { return _useWeekDays;}
    int *GetUseWeekDaysRef()                { return &_useWeekDays;}
    void SetWeekDays(const char* theValue);
    const char  *GetWeekDays();
    int *GetWeekMonRef()                { return &_weekMon;}
    int *GetWeekTueRef()                { return &_weekTue;}
    int *GetWeekWedRef()                { return &_weekWed;}
    int *GetWeekThuRef()                { return &_weekThu;}
    int *GetWeekFriRef()                { return &_weekFri;}
    int *GetWeekSatRef()                { return &_weekSat;}
    int *GetWeekSunRef()                { return &_weekSun;}
    
    
    const char *ToString();
    const char *CreateUpdateSqlString(Database *db);
    const char *CreateInsertSqlString(Database *db);
    const char *CreateDeleteSqlString(Database *db);

};

class cXxvAutoTimers : public cList<cXxvAutoTimer> {};

#endif
