/*
 * Copyright (C) 2022, KylinSoft Co., Ltd.
 *
 * 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 3 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 <https://www.gnu.org/licenses/>.
 *
 * Authors: Xin Li <lixin@kylinos.cn>
 */
#ifndef MMediaPlaylist_H
#define MMediaPlaylist_H

#include <QObject>
#include <QDebug>
#include <QUrl>
#include <QDateTime>

class MMediaContent
{

public:
    MMediaContent(QUrl url);
    QUrl canonicalUrl() const;

private:
    QUrl m_url;
};


class MMediaPlaylist : public QObject
{
    Q_OBJECT
public:
    enum PlaybackMode { CurrentItemOnce = 0, CurrentItemInLoop, Sequential, Loop, Random };
    MMediaPlaylist(QObject *parent = nullptr);

    QString getPlayFileName();
    int currentIndex() const;
    bool addMedia(const QUrl &items);
    void next();
    void previous();
    void setCurrentIndex(int index);
    PlaybackMode playbackMode() const;
    void setPlaybackMode(PlaybackMode mode);
    int mediaCount() const;
    MMediaContent media(int index) const;
    bool clear();
    bool removeMedia(int pos);
public slots:
    void palyFinish();

private:
    int randomIndex();
    QList<QUrl> m_playerList;
    int m_index = 0;
    PlaybackMode m_playbackMode = Loop;
signals:
    void currentIndexChanged(int);
    void playbackModeChanged(PlaybackMode);
    void autoPlay(MMediaPlaylist::PlaybackMode playbackMode);
    void stop();
};

#endif // MMediaPlaylist_H
