"""
    <This library provides a Python interface for the Telegram Bot API>
    Copyright (C) <2015> <Jacopo De Luca>

    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 <http://www.gnu.org/licenses/>.
"""
from Object.AUFile import AUFile
from Object.PhotoSize import PhotoSize


class Video(AUFile):
    """
    This object represents a video file.
    """

    def __init__(self, file_id, width, height, duration, thumb=None, mime_type="", file_size=0):
        """

        :param file_id: Unique identifier for this file
        :type file_id: str
        :param width: Video width as defined by sender
        :type width: int
        :param height: Video height as defined by sender
        :type height: int
        :param duration: Duration of the video in seconds as defined by sender
        :type duration: int
        :param thumb: Optional. Video thumbnail
        :type thumb: PhotoSize
        :param mime_type: Optional. Mime type of a file as defined by sender
        :type mime_type: str
        :param file_size: Optional. File size
        :type file_size: int
        """
        super().__init__(file_id, file_size, mime_type=mime_type)
        self.width = width
        self.height = height
        self.duration = duration
        self.thumb = thumb

    @staticmethod
    def build_from_json(jvideo):
        """

        :param jvideo: A dictionary that contains JSON-parsed object
        :type jvideo: dict
        :rtype: Video
        """
        thumb = None
        mime_type = ""
        file_size = 0
        if 'thumb' in jvideo.keys():
            thumb = PhotoSize.build_from_json(jvideo['thumb'])
        if 'mime_type' in jvideo.keys():
            mime_type = jvideo['mime_type']
        if 'file_size' in jvideo.keys():
            file_size = int(jvideo['file_size'])
        return Video(jvideo['file_id'], int(jvideo['width']), int(jvideo['height']), int(jvideo['duration']), thumb,
                     mime_type, file_size)
