# -*- coding: utf-8 -*-

"""
swaggerpetstoreopenapi30

This file was automatically generated by APIMATIC v3.0 (
 https://www.apimatic.io ).
"""

from swaggerpetstoreopenapi30.api_helper import APIHelper
from swaggerpetstoreopenapi30.configuration import Server
from swaggerpetstoreopenapi30.utilities.file_wrapper import FileWrapper
from swaggerpetstoreopenapi30.controllers.base_controller import BaseController
from apimatic_core.request_builder import RequestBuilder
from apimatic_core.response_handler import ResponseHandler
from apimatic_core.types.parameter import Parameter
from swaggerpetstoreopenapi30.http.http_method_enum import HttpMethodEnum
from apimatic_core.authentication.multiple.single_auth import Single
from swaggerpetstoreopenapi30.models.pet import Pet
from swaggerpetstoreopenapi30.models.pet_image import PetImage
from swaggerpetstoreopenapi30.exceptions.api_exception import APIException


class PetController(BaseController):

    """A Controller to access Endpoints in the swaggerpetstoreopenapi30 API."""
    def __init__(self, config):
        super(PetController, self).__init__(config)

    def update_pet(self,
                   name,
                   photo_urls,
                   id=None,
                   category=None,
                   tags=None,
                   pet_status=None):
        """Does a PUT request to /pet.

        Update an existing pet by Id

        Args:
            name (str): The request form parameter.
            photo_urls (List[str]): The request form parameter.
            id (int, optional): The request form parameter.
            category (Category, optional): The request form parameter.
            tags (List[Tag], optional): The request form parameter.
            pet_status (PetStatusEnum, optional): pet status in the store

        Returns:
            Pet: Response from the API. Successful operation

        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.

        """

        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path('/pet')
            .http_method(HttpMethodEnum.PUT)
            .form_param(Parameter()
                        .key('name')
                        .value(name))
            .form_param(Parameter()
                        .key('photoUrls')
                        .value(photo_urls))
            .form_param(Parameter()
                        .key('id')
                        .value(id))
            .form_param(Parameter()
                        .key('category')
                        .value(category))
            .form_param(Parameter()
                        .key('tags')
                        .value(tags))
            .form_param(Parameter()
                        .key('petStatus')
                        .value(pet_status))
            .header_param(Parameter()
                          .key('content-type')
                          .value('application/x-www-form-urlencoded'))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(Pet.from_dictionary)
            .local_error('400', 'Invalid ID supplied', APIException)
            .local_error('404', 'Pet not found', APIException)
            .local_error('405', 'Validation exception', APIException)
        ).execute()

    def add_pet(self,
                name,
                photo_urls,
                id=None,
                category=None,
                tags=None,
                pet_status=None):
        """Does a POST request to /pet.

        Add a new pet to the store

        Args:
            name (str): The request form parameter.
            photo_urls (List[str]): The request form parameter.
            id (int, optional): The request form parameter.
            category (Category, optional): The request form parameter.
            tags (List[Tag], optional): The request form parameter.
            pet_status (PetStatusEnum, optional): pet status in the store

        Returns:
            Pet: Response from the API. Successful operation

        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.

        """

        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path('/pet')
            .http_method(HttpMethodEnum.POST)
            .form_param(Parameter()
                        .key('name')
                        .value(name))
            .form_param(Parameter()
                        .key('photoUrls')
                        .value(photo_urls))
            .form_param(Parameter()
                        .key('id')
                        .value(id))
            .form_param(Parameter()
                        .key('category')
                        .value(category))
            .form_param(Parameter()
                        .key('tags')
                        .value(tags))
            .form_param(Parameter()
                        .key('petStatus')
                        .value(pet_status))
            .header_param(Parameter()
                          .key('content-type')
                          .value('application/x-www-form-urlencoded'))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(Pet.from_dictionary)
            .local_error('405', 'Invalid input', APIException)
        ).execute()

    def find_pets_by_status(self,
                            status='available'):
        """Does a GET request to /pet/findByStatus.

        Multiple status values can be provided with comma separated strings

        Args:
            status (StatusEnum, optional): Status values that need to be
                considered for filter

        Returns:
            List[Pet]: Response from the API. successful operation

        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.

        """

        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path('/pet/findByStatus')
            .http_method(HttpMethodEnum.GET)
            .query_param(Parameter()
                         .key('status')
                         .value(status))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(Pet.from_dictionary)
            .local_error('400', 'Invalid status value', APIException)
        ).execute()

    def find_pets_by_tags(self,
                          tags=None):
        """Does a GET request to /pet/findByTags.

        Multiple tags can be provided with comma separated strings. Use tag1,
        tag2, tag3 for testing.

        Args:
            tags (List[str], optional): Tags to filter by

        Returns:
            List[Pet]: Response from the API. successful operation

        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.

        """

        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path('/pet/findByTags')
            .http_method(HttpMethodEnum.GET)
            .query_param(Parameter()
                         .key('tags')
                         .value(tags))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(Pet.from_dictionary)
            .local_error('400', 'Invalid tag value', APIException)
        ).execute()

    def get_pet_by_id(self,
                      pet_id):
        """Does a GET request to /pet/{petId}.

        Returns a single pet

        Args:
            pet_id (int): ID of pet to return

        Returns:
            Pet: Response from the API. successful operation

        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.

        """

        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path('/pet/{petId}')
            .http_method(HttpMethodEnum.GET)
            .template_param(Parameter()
                            .key('petId')
                            .value(pet_id)
                            .should_encode(True))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .auth(Single('api_key'))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(Pet.from_dictionary)
            .local_error('400', 'Invalid ID supplied', APIException)
            .local_error('404', 'Pet not found', APIException)
        ).execute()

    def update_pet_with_form(self,
                             pet_id,
                             name=None,
                             status=None):
        """Does a POST request to /pet/{petId}.

        Args:
            pet_id (int): ID of pet that needs to be updated
            name (str, optional): Name of pet that needs to be updated
            status (str, optional): Status of pet that needs to be updated

        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.

        """

        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path('/pet/{petId}')
            .http_method(HttpMethodEnum.POST)
            .template_param(Parameter()
                            .key('petId')
                            .value(pet_id)
                            .should_encode(True))
            .query_param(Parameter()
                         .key('name')
                         .value(name))
            .query_param(Parameter()
                         .key('status')
                         .value(status))
        ).execute()

    def delete_pet(self,
                   pet_id,
                   api_key=None):
        """Does a DELETE request to /pet/{petId}.

        delete a pet

        Args:
            pet_id (int): Pet id to delete
            api_key (str, optional): The request header parameter.

        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.

        """

        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path('/pet/{petId}')
            .http_method(HttpMethodEnum.DELETE)
            .template_param(Parameter()
                            .key('petId')
                            .value(pet_id)
                            .should_encode(True))
            .header_param(Parameter()
                          .key('api_key')
                          .value(api_key))
        ).execute()

    def upload_file(self,
                    pet_id,
                    additional_metadata=None,
                    body=None):
        """Does a POST request to /pet/{petId}/uploadImage.

        Args:
            pet_id (int): ID of pet to update
            additional_metadata (str, optional): Additional Metadata
            body (typing.BinaryIO, optional): The request form parameter.

        Returns:
            PetImage: Response from the API. successful operation

        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.

        """

        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path('/pet/{petId}/uploadImage')
            .http_method(HttpMethodEnum.POST)
            .template_param(Parameter()
                            .key('petId')
                            .value(pet_id)
                            .should_encode(True))
            .query_param(Parameter()
                         .key('additionalMetadata')
                         .value(additional_metadata))
            .multipart_param(Parameter()
                             .key('body')
                             .value(body)
                             .default_content_type('application/octet-stream'))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(PetImage.from_dictionary)
        ).execute()
