# -*- 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.zobject_metadata import ZobjectMetadata


class ZobjectController(BaseController):

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

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

    def zobjects_get(self,
                     id=None,
                     custom=None,
                     q=None,
                     order=None,
                     sort=None,
                     page=None,
                     per_page=None,
                     zobject_type=None):
        """Does a GET request to /zobjects.

        List Zobject Types

        Args:
            id (string, optional): Filter by ID + Examples     +
                `id=549dc72d636872c09d1f0000`     + use
                `id!=549dc72d636872c09d1f0000` to exclude by ID
            custom (string, optional): Filter records by custom attribues +
                Example: color=blue
            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
            zobject_type (string, optional): TODO: type description here.

        Returns:
            ZobjectMetadata: 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 = '/zobjects'
        _query_builder = self.config.get_base_uri()
        _query_builder += _url_path
        _query_parameters = {
            'id': id,
            'custom': custom,
            'q': q,
            'order': order,
            'sort': sort,
            'page': page,
            'per_page': per_page,
            'zobject_type': zobject_type
        }
        _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, ZobjectMetadata.from_dictionary)

        return decoded

    def zobjects_post(self,
                      body,
                      id=None,
                      custom=None,
                      zobject_type=None,
                      page=None,
                      per_page=None,
                      q=None,
                      order=None,
                      sort=None):
        """Does a POST request to /zobjects.

        Create Zobject

        Args:
            body (ZobjectRequest): TODO: type description here.
            id (string, optional): TODO: type description here.
            custom (string, optional): TODO: type description here.
            zobject_type (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.
            order (string, optional): TODO: type description here.
            sort (string, optional): TODO: type description here.

        Returns:
            ZobjectMetadata: 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 = '/zobjects'
        _query_builder = self.config.get_base_uri()
        _query_builder += _url_path
        _query_parameters = {
            'id': id,
            'custom': custom,
            'zobject_type': zobject_type,
            'page': page,
            'per_page': per_page,
            'q': q,
            'order': order,
            'sort': sort
        }
        _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, ZobjectMetadata.from_dictionary)

        return decoded

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

        Retrieve Zobject

        Args:
            id (string): ID of the record

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

        return decoded

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

        Update Zobject

        Args:
            id (string): ID of the record
            body (ZobjectRequest): TODO: type description here.

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

        return decoded

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

        Delete Zobject

        Args:
            id (string): ID of the record

        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 = '/zobjects/{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)
