/*
 * Copyright 2010  Jonas Emanuel Müller <zanoi@zanoi.net>
 *
 * This program 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; either version 2 of 
 * the License, or (at your option) any later version.

 * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef EPISODEMODEL_H
#define EPISODEMODEL_H

#include "config.h" //krazy:exclude=includes

class QModelIndex;
class QRegExp;

#include <QSqlRelationalTableModel>
#include <QObject>

namespace Videocatcher {

enum {
    Episode_Id = 0,
    Episode_Status = 1,
    Episode_Video_Size = 2,
    Episode_Title = 3,
    Episode_Description = 4,
    Episode_Channel_Id = 5,
    Episode_Date_Published = 6,
    Episode_Video_Url = 7,
    Episode_Video_Path = 8,
};

enum {
    Episode_Status_Not_Downloaded = -1,
    Episode_Status_Downloaded = -2,
    Episode_Status_Paused = -3,
    Episode_Status_Cancelled = -4,
    Episode_Status_New = -5,
    Episode_Status_Deleted = -6,
    Episode_Status_Unavailable = -7
};
    

class EpisodeModel : public QSqlRelationalTableModel
{
public:
    explicit EpisodeModel(QObject *parent = 0);
    ~EpisodeModel();

    QModelIndex addEpisode(const QString &title, const QString &description, const int channelId, const double datePublished, const QString &videoUrl, const double videoSize);
    QModelIndex findById(const int id) const;
    QModelIndex findByTitle(const QString &title) const;
    QModelIndex findByUrl(const QString &url) const;
  
    QModelIndexList findAllByTitle(const QString &title) const;
    QModelIndexList findAllByUrl(const QString &url) const;
    QModelIndexList findAllbyChannelId(const int channelId) const;
    QModelIndexList findDownloadedEpisodes(const int channelId) const;
    QModelIndexList findDownloadingEpisodes() const;
    QModelIndexList findByVideoPath(const QRegExp &regExp) const;
   
    int id(const QModelIndex &row) const;
    int status(const QModelIndex &row) const;
    QString title(const QModelIndex &row) const;
    QString description(const QModelIndex &row) const;
    int channelId(const QModelIndex &row) const;
    double videoSize(const QModelIndex &row) const;
    QString videoUrl(const QModelIndex &row) const;
    QString videoPath(const QModelIndex &row) const;
    double datePublished(const QModelIndex &row) const;
    
    bool setStatus(const QModelIndex &row, const int data);
    bool setTitle(const QModelIndex &row, const QString &data);
    bool setDescription(const QModelIndex &row, const QString &data);
    bool setChannelId(const QModelIndex &row, const int data);
    bool setVideoSize(const QModelIndex &row, const double data);
    bool setVideoUrl(const QModelIndex &row, const QString &data);
    bool setVideoPath(const QModelIndex &row, const QString &data);
    bool setDatePublished(const QModelIndex &row, const double data);
    
    bool removeEpisode(const QModelIndex &index);
    bool removeEpisodes(const QModelIndexList &index);
   
    QModelIndex findNewest(const int channelId);
    
protected:
    struct EpisodeModelPrivate;
    EpisodeModelPrivate *const d;
};

} //namespace Videocatcher

#endif
