# -*- 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.content_rule_metadata import ContentRuleMetadata


class CategoryContentRulesController(BaseController):

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

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

    def categories_content_rules_by_category_id_get(self,
                                                    category_id):
        """Does a GET request to /categories/{category_id}/content_rules.

        List Content Rules for a Category

        Args:
            category_id (string): category ID

        Returns:
            list of ContentRuleMetadata: 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 = '/categories/{category_id}/content_rules'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'category_id': {'value': category_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, ContentRuleMetadata.from_dictionary)

        return decoded

    def categories_content_rules_by_category_id_post(self,
                                                     body,
                                                     category_id):
        """Does a POST request to /categories/{category_id}/content_rules.

        Create Category Content Rule

        Args:
            body (ContentRuleRequest): TODO: type description here.
            category_id (string): TODO: type description here.

        Returns:
            ContentRuleMetadata: 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 = '/categories/{category_id}/content_rules'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'category_id': {'value': category_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.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, ContentRuleMetadata.from_dictionary)

        return decoded

    def categories_content_rules_by_category_id_and_id_get(self,
                                                           category_id,
                                                           id):
        """Does a GET request to /categories/{category_id}/content_rules/{id}.

        View Category Content Rule

        Args:
            category_id (string): category ID
            id (string): content rule ID

        Returns:
            ContentRuleMetadata: 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 = '/categories/{category_id}/content_rules/{id}'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'category_id': {'value': category_id, 'encode': True},
            '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, ContentRuleMetadata.from_dictionary)

        return decoded

    def categories_content_rules_by_category_id_and_id_put(self,
                                                           category_id,
                                                           id,
                                                           body):
        """Does a PUT request to /categories/{category_id}/content_rules/{id}.

        Update Category Content Rule

        Args:
            category_id (string): category ID
            id (string): content rule ID
            body (ContentRuleRequest): TODO: type description here.

        Returns:
            ContentRuleMetadata: 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 = '/categories/{category_id}/content_rules/{id}'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'category_id': {'value': category_id, 'encode': True},
            '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, ContentRuleMetadata.from_dictionary)

        return decoded

    def categories_content_rules_by_category_id_and_id_delete(self,
                                                              category_id,
                                                              id):
        """Does a DELETE request to /categories/{category_id}/content_rules/{id}.

        Delete Category Content Rule

        Args:
            category_id (string): category ID
            id (string): content rule ID

        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 = '/categories/{category_id}/content_rules/{id}'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'category_id': {'value': category_id, 'encode': True},
            '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)
