# -*- 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.device_category import DeviceCategory


class DeviceCategoriesController(BaseController):

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

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

    def device_categories_get(self,
                              title=None,
                              id=None,
                              created_at=None,
                              q=None,
                              order=None,
                              sort=None,
                              page=None,
                              per_page=None):
        """Does a GET request to /device_categories.

        List Devices Categories

        Args:
            title (string, optional): Filter by title
            id (string, optional): Filter by id + Examples     +
                `id=593030d74d740d0053000012`     + use
                `id!=593030d74d740d0053000012` to exclude by id
            created_at (string, optional): Filter by when the category was
                created
            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

        Returns:
            list of DeviceCategory: 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 = '/device_categories'
        _query_builder = self.config.get_base_uri()
        _query_builder += _url_path
        _query_parameters = {
            'title': title,
            'id': id,
            'created_at': created_at,
            'q': q,
            'order': order,
            'sort': sort,
            'page': page,
            'per_page': per_page
        }
        _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, DeviceCategory.from_dictionary)

        return decoded

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

        View Device Category

        Args:
            id (string): ID of device category

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

        return decoded
