# -*- coding: utf-8 -*-

"""
zypev1

This file was automatically generated by APIMATIC v3.0 (
 https://www.apimatic.io ).
"""

from zypev1.api_helper import APIHelper
from zypev1.configuration import Server
from zypev1.controllers.base_controller import BaseController
from zypev1.models.video_metadata import VideoMetadata


class VideosController(BaseController):

    """A Controller to access Endpoints in the zypev1 API."""

    def __init__(self, config, call_back=None):
        super(VideosController, self).__init__(config, call_back)

    def videos_get(self,
                   active=None,
                   category=None,
                   created_at=None,
                   friendly_title=None,
                   id=None,
                   hulu_id=None,
                   vimeo_id=None,
                   youtube_id=None,
                   zobject_id=None,
                   mature_content=None,
                   order=None,
                   on_air=None,
                   page=None,
                   per_page=None,
                   published_at=None,
                   q=None,
                   sort=None,
                   source_id=None,
                   mtype=None,
                   dpt=None,
                   crunchyroll_id=None):
        """Does a GET request to /videos.

        List Videos

        Args:
            active (bool, optional): Filter by active, inactive, or all
                records
            category (string, optional): Filter by category value + Examples  
                + `category[genre][]=drama`     + use
                `category![genre][]=drama` to exclude by category value
            created_at (date, optional): Filter by created at date using times
                in ISO8601 format + Examples     + `2017-01-01T00:00:00-00:00`
                + `1483228800`
            friendly_title (string, optional): Filter by friendly title
            id (string, optional): Filter by id + Examples     +
                `id=3049df039402ld3029f930`     + use
                `id!=3049df039402ld3029f930` to exclude by id
            hulu_id (string, optional): Filter by Hulu ID
            vimeo_id (string, optional): Filter by Vimeo ID
            youtube_id (string, optional): Filter by YouTube ID
            zobject_id (string, optional): Filter by Zobject ID
            mature_content (bool, optional): Filter records flagged as mature
            order (string, optional): Filter by ascending or descending order
                + Examples     + `asc`     + `desc`
            on_air (bool, optional): Filter records that are either on or off
                air
            page (float, optional): Number of pages to return
            per_page (float, optional): Number of records to return per page
            published_at (date, optional): Filter records by published date
                using times in ISO8601 format + Examples:     +
                `2017-01-01T00:00:00-00:00`     + `1483228800`
            q (string, optional): Filter by keyword
            sort (string, optional): Sort on the specified field
            source_id (string, optional): Filter by source identifier
            mtype (string, optional): Filter by type + Examples:     + `zype` 
                + `hulu`     + `youtube`     + `crunchyroll`
            dpt (string, optional): TODO: type description here.
            crunchyroll_id (string, optional): TODO: type description here.

        Returns:
            list of VideoMetadata: Response from the API.

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        # Prepare query URL
        _url_path = '/videos'
        _query_builder = self.config.get_base_uri()
        _query_builder += _url_path
        _query_parameters = {
            'active': active,
            'category': category,
            'created_at': created_at,
            'friendly_title': friendly_title,
            'id': id,
            'hulu_id': hulu_id,
            'vimeo_id': vimeo_id,
            'youtube_id': youtube_id,
            'zobject_id': zobject_id,
            'mature_content': mature_content,
            'order': order,
            'on_air': on_air,
            'page': page,
            'per_page': per_page,
            'published_at': published_at,
            'q': q,
            'sort': sort,
            'source_id': source_id,
            'type': mtype,
            'dpt': dpt,
            'crunchyroll_id': crunchyroll_id
        }
        _query_builder = APIHelper.append_url_with_query_parameters(
            _query_builder,
            _query_parameters
        )
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            'accept': 'application/json'
        }

        # Prepare and execute request
        _request = self.config.http_client.get(_query_url, headers=_headers)
        _response = self.execute_request(_request)
        self.validate_response(_response)

        decoded = APIHelper.json_deserialize(_response.text, VideoMetadata.from_dictionary)

        return decoded

    def videos_post(self,
                    body,
                    active=None,
                    category=None,
                    created_at=None,
                    dpt=None,
                    crunchyroll_id=None,
                    friendly_title=None,
                    id=None,
                    hulu_id=None,
                    vimeo_id=None,
                    youtube_id=None,
                    zobject_id=None,
                    mature_content=None,
                    order=None,
                    on_air=None,
                    page=None,
                    per_page=None,
                    published_at=None,
                    q=None,
                    sort=None,
                    source_id=None,
                    mtype=None):
        """Does a POST request to /videos.

        Create a New Video

        Args:
            body (VideoRequest): TODO: type description here.
            active (string, optional): TODO: type description here.
            category (string, optional): TODO: type description here.
            created_at (string, optional): TODO: type description here.
            dpt (string, optional): TODO: type description here.
            crunchyroll_id (string, optional): TODO: type description here.
            friendly_title (string, optional): TODO: type description here.
            id (string, optional): TODO: type description here.
            hulu_id (string, optional): TODO: type description here.
            vimeo_id (string, optional): TODO: type description here.
            youtube_id (string, optional): TODO: type description here.
            zobject_id (string, optional): TODO: type description here.
            mature_content (string, optional): TODO: type description here.
            order (string, optional): TODO: type description here.
            on_air (string, optional): TODO: type description here.
            page (string, optional): TODO: type description here.
            per_page (string, optional): TODO: type description here.
            published_at (string, optional): TODO: type description here.
            q (string, optional): TODO: type description here.
            sort (string, optional): TODO: type description here.
            source_id (string, optional): TODO: type description here.
            mtype (string, optional): TODO: type description here.

        Returns:
            VideoMetadata: Response from the API.

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        # Prepare query URL
        _url_path = '/videos'
        _query_builder = self.config.get_base_uri()
        _query_builder += _url_path
        _query_parameters = {
            'active': active,
            'category': category,
            'created_at': created_at,
            'dpt': dpt,
            'crunchyroll_id': crunchyroll_id,
            'friendly_title': friendly_title,
            'id': id,
            'hulu_id': hulu_id,
            'vimeo_id': vimeo_id,
            'youtube_id': youtube_id,
            'zobject_id': zobject_id,
            'mature_content': mature_content,
            'order': order,
            'on_air': on_air,
            'page': page,
            'per_page': per_page,
            'published_at': published_at,
            'q': q,
            'sort': sort,
            'source_id': source_id,
            'type': mtype
        }
        _query_builder = APIHelper.append_url_with_query_parameters(
            _query_builder,
            _query_parameters
        )
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            'accept': 'application/json',
            'content-type': 'application/json; charset=utf-8'
        }

        # Prepare and execute request
        _request = self.config.http_client.post(_query_url, headers=_headers, parameters=APIHelper.json_serialize(body))
        _response = self.execute_request(_request)
        self.validate_response(_response)

        decoded = APIHelper.json_deserialize(_response.text, VideoMetadata.from_dictionary)

        return decoded

    def videos_by_id_get(self,
                         id):
        """Does a GET request to /videos/{id}.

        View Video

        Args:
            id (string): ID of video

        Returns:
            VideoMetadata: Response from the API.

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        # Prepare query URL
        _url_path = '/videos/{id}'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'id': {'value': id, 'encode': True}
        })
        _query_builder = self.config.get_base_uri()
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            'accept': 'application/json'
        }

        # Prepare and execute request
        _request = self.config.http_client.get(_query_url, headers=_headers)
        _response = self.execute_request(_request)
        self.validate_response(_response)

        decoded = APIHelper.json_deserialize(_response.text, VideoMetadata.from_dictionary)

        return decoded

    def videos_by_id_put(self,
                         id,
                         body):
        """Does a PUT request to /videos/{id}.

        Update Video

        Args:
            id (string): ID of video
            body (VideoRequest): TODO: type description here.

        Returns:
            VideoMetadata: Response from the API.

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        # Prepare query URL
        _url_path = '/videos/{id}'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'id': {'value': id, 'encode': True}
        })
        _query_builder = self.config.get_base_uri()
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            'accept': 'application/json',
            'content-type': 'application/json; charset=utf-8'
        }

        # Prepare and execute request
        _request = self.config.http_client.put(_query_url, headers=_headers, parameters=APIHelper.json_serialize(body))
        _response = self.execute_request(_request)
        self.validate_response(_response)

        decoded = APIHelper.json_deserialize(_response.text, VideoMetadata.from_dictionary)

        return decoded

    def videos_add_zobjects_by_id_put(self,
                                      id,
                                      body):
        """Does a PUT request to /videos/{id}/add_zobjects.

        Add Zobject(s) to Video

        Args:
            id (string): ID of video
            body (AddZobjectSToVideoRequest): TODO: type description here.

        Returns:
            VideoMetadata: Response from the API.

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        # Prepare query URL
        _url_path = '/videos/{id}/add_zobjects'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'id': {'value': id, 'encode': True}
        })
        _query_builder = self.config.get_base_uri()
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            'accept': 'application/json',
            'content-type': 'application/json; charset=utf-8'
        }

        # Prepare and execute request
        _request = self.config.http_client.put(_query_url, headers=_headers, parameters=APIHelper.json_serialize(body))
        _response = self.execute_request(_request)
        self.validate_response(_response)

        decoded = APIHelper.json_deserialize(_response.text, VideoMetadata.from_dictionary)

        return decoded

    def videos_remove_zobjects_by_id_put(self,
                                         id,
                                         body):
        """Does a PUT request to /videos/{id}/remove_zobjects.

        Remove Zobject(s) from Video

        Args:
            id (string): ID of video
            body (object): TODO: type description here.

        Returns:
            VideoMetadata: Response from the API.

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        # Prepare query URL
        _url_path = '/videos/{id}/remove_zobjects'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'id': {'value': id, 'encode': True}
        })
        _query_builder = self.config.get_base_uri()
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            'accept': 'application/json',
            'content-type': 'application/json; charset=utf-8'
        }

        # Prepare and execute request
        _request = self.config.http_client.put(_query_url, headers=_headers, parameters=APIHelper.json_serialize(body))
        _response = self.execute_request(_request)
        self.validate_response(_response)

        decoded = APIHelper.json_deserialize(_response.text, VideoMetadata.from_dictionary)

        return decoded

    def videos_download_by_id_get(self,
                                  id):
        """Does a GET request to /videos/{id}/download.

        Download original source file

        Args:
            id (string): ID of video

        Returns:
            string: Response from the API.

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        # Prepare query URL
        _url_path = '/videos/{id}/download'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'id': {'value': id, 'encode': True}
        })
        _query_builder = self.config.get_base_uri()
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare and execute request
        _request = self.config.http_client.get(_query_url)
        _response = self.execute_request(_request)
        self.validate_response(_response)

        decoded = _response.text

        return decoded
