#ifndef VIDEO_HPP_INCLUDED
#define VIDEO_HPP_INCLUDED

#define VIDEO_SPEED_MIN 0
#define VIDEO_SPEED_MAX 4
#define VIDEO_SPEED_STEP 1
#define CURRENT_TIME_MAX 60

enum VideoState { STOPPED, PAUSED, PLAYING };

class Video {
    private:
        VideoState state;
        int videoSpeed;
        int currentTime;

    public:
        Video() : state(STOPPED), videoSpeed(1), currentTime(VIDEO_SPEED_MIN) {}
        Video(VideoState s, int vs, int ct) : state(s), videoSpeed(vs), currentTime(ct) {}
        Video(const Video& v) : state(v.state), videoSpeed(v.videoSpeed), currentTime(v.currentTime) {}

        bool increaseSpeed() {
            if(state != STOPPED && videoSpeed+VIDEO_SPEED_STEP <= VIDEO_SPEED_MAX) {
                videoSpeed += VIDEO_SPEED_STEP;
                return true;
            }

            return false;
        }

        bool decreaseSpeed() {
            if(state != STOPPED && videoSpeed-VIDEO_SPEED_STEP >= VIDEO_SPEED_MIN) {
                videoSpeed -= VIDEO_SPEED_STEP;
                return true;
            }

            return false;
        }

        bool setCurrentTime(int ct) {
            if(state != STOPPED && ct >= VIDEO_SPEED_MIN && ct <= CURRENT_TIME_MAX) {
                currentTime = ct;
                return true;
            }

            return false;
        }

        bool play() {
            if(state != PLAYING) {
                state = PLAYING;
                return true;
            }

            return false;
        }

        bool pause() {
            if(state == PLAYING) {
                state = PAUSED;
                return true;
            }

            return false;
        }

        bool stop() {
            if(state != STOPPED) {
                state = STOPPED;
                videoSpeed = VIDEO_SPEED_STEP;
                currentTime = VIDEO_SPEED_MIN;
                return true;
            }

            return false;
        }

        void watch(int seconds) {
            if(state == PLAYING) {
                currentTime += videoSpeed * seconds;

                if(currentTime == CURRENT_TIME_MAX) {
                    state = STOPPED;
                    videoSpeed = VIDEO_SPEED_STEP;
                    currentTime = VIDEO_SPEED_MIN;
                }
            }
        }

        VideoState getState() const { return state; }
        int getVideoSpeed() const { return videoSpeed; }
        int getCurrentTime() const { return currentTime; }
};

#endif // VIDEO_HPP_INCLUDED

