# -*- 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


class PlayersController(BaseController):

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

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

    def embed_format_by_video_id_get(self,
                                     video_id,
                                     autoplay=None,
                                     audio=None,
                                     download=None,
                                     dvr=None):
        """Does a GET request to /embed/{video_id}.format.

        The full URL will look like
        https://player.zype.com/embed/[video_id].[format]. The format for the
        player response must be one of Iframes, JavaScript or JSON players 
        depending on device capabilities (Example: html, js, json)

        Args:
            video_id (string): ID of video
            autoplay (bool, optional): Whether or not to autoplay on page
                load
            audio (bool, optional): Request audio only
            download (bool, optional): Request download only player
            dvr (bool, optional): Enable DVR for Zype Live events

        Returns:
            object: 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 = '/embed/{video_id}.format'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'video_id': {'value': video_id, 'encode': True}
        })
        _query_builder = self.config.get_base_uri()
        _query_builder += _url_path
        _query_parameters = {
            'autoplay': autoplay,
            'audio': audio,
            'download': download,
            'dvr': dvr
        }
        _query_builder = APIHelper.append_url_with_query_parameters(
            _query_builder,
            _query_parameters
        )
        _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
