# -*- 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.redemption_code_metadata import RedemptionCodeMetadata


class RedemptionCodesController(BaseController):

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

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

    def redemption_codes_get(self,
                             code,
                             id=None,
                             created_at=None,
                             updated_at=None,
                             expiration_date=None,
                             redeemed_at=None,
                             pass_plan_id=None,
                             plan_id=None,
                             playlist_id=None,
                             transaction_id=None,
                             video_id=None,
                             q=None,
                             order=None,
                             sort=None,
                             page=None,
                             per_page=None,
                             api_key=None):
        """Does a GET request to /redemption_codes.

        List Redemption Codes

        Args:
            code (string): Filter by code
            id (string, optional): Filter by ID + Examples     +
                `id=59b2ffaac8a589000100001b`     + use
                `id!=59b2ffaac8a589000100001b` to exclude by ID
            created_at (date, optional): Filter by created at date using times
                in ISO8601 format Note: Range filters can be applied by adding
                a suffix: ‘.gt’, ‘.gte’, ‘.lt’, ‘lte’ (Example:
                expires_at.gte) + Examples     + `2017-01-01T00:00:00-00:00` -
                in ISO8601 format     + `1483228800` - Unix timestamps
            updated_at (date, optional): Filter by created at date using times
                in ISO8601 format Note: Range filters can be applied by adding
                a suffix: ‘.gt’, ‘.gte’, ‘.lt’, ‘lte’ (Example:
                expires_at.gte) + Examples     + `2017-01-01T00:00:00-00:00` -
                in ISO8601 format     + `1483228800` - Unix timestamps
            expiration_date (date, optional): Filter by created at date using
                times in ISO8601 format Note: Range filters can be applied by
                adding a suffix: ‘.gt’, ‘.gte’, ‘.lt’, ‘lte’ (Example:
                expires_at.gte) + Examples     + `2017-01-01T00:00:00-00:00` -
                in ISO8601 format     + `1483228800` - Unix timestamps
            redeemed_at (date, optional): Filter by created at date using
                times in ISO8601 format Note: Range filters can be applied by
                adding a suffix: ‘.gt’, ‘.gte’, ‘.lt’, ‘lte’ (Example:
                expires_at.gte) + Examples     + `2017-01-01T00:00:00-00:00` -
                in ISO8601 format     + `1483228800` - Unix timestamps
            pass_plan_id (string, optional): Filter records by a pass plan ID
            plan_id (string, optional): Filter records by plan ID
            playlist_id (string, optional): Filter records by playlist ID
            transaction_id (string, optional): Filter records by transaction
                ID
            video_id (string, optional): Filter records by video ID
            q (string, optional): Filter by keyword
            order (string, optional): Filter by ascending or descending order
                + Examples     + asc     + desc
            sort (string, optional): Sort on the specified field
            page (float, optional): Number of pages to return
            per_page (float, optional): Number of records to return per page
            api_key (string, optional): TODO: type description here.

        Returns:
            RedemptionCodeMetadata: 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 = '/redemption_codes'
        _query_builder = self.config.get_base_uri()
        _query_builder += _url_path
        _query_parameters = {
            'code': code,
            'id': id,
            'created_at': created_at,
            'updated_at': updated_at,
            'expiration_date': expiration_date,
            'redeemed_at': redeemed_at,
            'pass_plan_id': pass_plan_id,
            'plan_id': plan_id,
            'playlist_id': playlist_id,
            'transaction_id': transaction_id,
            'video_id': video_id,
            'q': q,
            'order': order,
            'sort': sort,
            'page': page,
            'per_page': per_page,
            'api_key': api_key
        }
        _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, RedemptionCodeMetadata.from_dictionary)

        return decoded

    def redemption_codes_post(self,
                              body,
                              id=None,
                              api_key=None,
                              code=None,
                              created_at=None,
                              expiration_date=None,
                              pass_plan_id=None,
                              plan_id=None,
                              playlist_id=None,
                              redeemed_at=None,
                              transaction_id=None,
                              updated_at=None,
                              video_id=None,
                              order=None,
                              sort=None,
                              page=None,
                              per_page=None,
                              q=None):
        """Does a POST request to /redemption_codes.

        Create Redemption Codes

        Args:
            body (RedemptionCodeRequest): TODO: type description here.
            id (string, optional): TODO: type description here.
            api_key (string, optional): TODO: type description here.
            code (string, optional): TODO: type description here.
            created_at (string, optional): TODO: type description here.
            expiration_date (string, optional): TODO: type description here.
            pass_plan_id (string, optional): TODO: type description here.
            plan_id (string, optional): TODO: type description here.
            playlist_id (string, optional): TODO: type description here.
            redeemed_at (string, optional): TODO: type description here.
            transaction_id (string, optional): TODO: type description here.
            updated_at (string, optional): TODO: type description here.
            video_id (string, optional): TODO: type description here.
            order (string, optional): TODO: type description here.
            sort (string, optional): TODO: type description here.
            page (string, optional): TODO: type description here.
            per_page (string, optional): TODO: type description here.
            q (string, optional): TODO: type description here.

        Returns:
            RedemptionCodeMetadata: 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 = '/redemption_codes'
        _query_builder = self.config.get_base_uri()
        _query_builder += _url_path
        _query_parameters = {
            'id': id,
            'api_key': api_key,
            'code': code,
            'created_at': created_at,
            'expiration_date': expiration_date,
            'pass_plan_id': pass_plan_id,
            'plan_id': plan_id,
            'playlist_id': playlist_id,
            'redeemed_at': redeemed_at,
            'transaction_id': transaction_id,
            'updated_at': updated_at,
            'video_id': video_id,
            'order': order,
            'sort': sort,
            'page': page,
            'per_page': per_page,
            'q': q
        }
        _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, RedemptionCodeMetadata.from_dictionary)

        return decoded

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

        View Redemption Code

        Args:
            id (string): ID of the redemption code

        Returns:
            RedemptionCodeMetadata: 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 = '/redemption_codes/{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, RedemptionCodeMetadata.from_dictionary)

        return decoded

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

        Update Redemption Code

        Args:
            id (string): ID of the redemption code
            body (RedemptionCodeRequest): TODO: type description here.

        Returns:
            RedemptionCodeMetadata: 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 = '/redemption_codes/{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, RedemptionCodeMetadata.from_dictionary)

        return decoded

    def redemption_codes_by_id_delete(self,
                                      id):
        """Does a DELETE request to /redemption_codes/{id}.

        Delete Redemption Code

        Args:
            id (string): ID of the redemption code

        Returns:
            void: 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 = '/redemption_codes/{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 and execute request
        _request = self.config.http_client.delete(_query_url)
        _response = self.execute_request(_request)
        self.validate_response(_response)
