# -*- 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.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 swaggerpetstoreopenapi30.models.user import User
from swaggerpetstoreopenapi30.exceptions.api_exception import APIException


class UserController(BaseController):

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

    def create_user(self,
                    id=None,
                    username=None,
                    first_name=None,
                    last_name=None,
                    email=None,
                    password=None,
                    phone=None,
                    user_status=None):
        """Does a POST request to /user.

        This can only be done by the logged in user.

        Args:
            id (int, optional): The request form parameter.
            username (str, optional): The request form parameter.
            first_name (str, optional): The request form parameter.
            last_name (str, optional): The request form parameter.
            email (str, optional): The request form parameter.
            password (str, optional): The request form parameter.
            phone (str, optional): The request form parameter.
            user_status (int, optional): User Status

        Returns:
            User: 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('/user')
            .http_method(HttpMethodEnum.POST)
            .form_param(Parameter()
                        .key('id')
                        .value(id))
            .form_param(Parameter()
                        .key('username')
                        .value(username))
            .form_param(Parameter()
                        .key('firstName')
                        .value(first_name))
            .form_param(Parameter()
                        .key('lastName')
                        .value(last_name))
            .form_param(Parameter()
                        .key('email')
                        .value(email))
            .form_param(Parameter()
                        .key('password')
                        .value(password))
            .form_param(Parameter()
                        .key('phone')
                        .value(phone))
            .form_param(Parameter()
                        .key('userStatus')
                        .value(user_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(User.from_dictionary)
        ).execute()

    def create_users_with_list_input(self,
                                     body=None):
        """Does a POST request to /user/createWithList.

        Creates list of users with given input array

        Args:
            body (List[User], optional): The request body parameter.

        Returns:
            User: 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('/user/createWithList')
            .http_method(HttpMethodEnum.POST)
            .header_param(Parameter()
                          .key('Content-Type')
                          .value('application/json'))
            .body_param(Parameter()
                        .value(body))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .body_serializer(APIHelper.json_serialize)
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(User.from_dictionary)
            .local_error('default', 'successful operation', APIException)
        ).execute()

    def login_user(self,
                   username=None,
                   password=None):
        """Does a GET request to /user/login.

        Args:
            username (str, optional): The user name for login
            password (str, optional): The password for login in clear text

        Returns:
            str: 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('/user/login')
            .http_method(HttpMethodEnum.GET)
            .query_param(Parameter()
                         .key('username')
                         .value(username))
            .query_param(Parameter()
                         .key('password')
                         .value(password))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .local_error('400', 'Invalid username/password supplied', APIException)
        ).execute()

    def logout_user(self):
        """Does a GET request to /user/logout.

        Returns:
            void: 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('/user/logout')
            .http_method(HttpMethodEnum.GET)
        ).execute()

    def get_user_by_name(self,
                         name):
        """Does a GET request to /user/{name}.

        Args:
            name (str): The name that needs to be fetched. Use user1 for
                testing.

        Returns:
            User: 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('/user/{name}')
            .http_method(HttpMethodEnum.GET)
            .template_param(Parameter()
                            .key('name')
                            .value(name)
                            .should_encode(True))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(User.from_dictionary)
            .local_error('400', 'Invalid username supplied', APIException)
            .local_error('404', 'User not found', APIException)
        ).execute()

    def update_user(self,
                    name,
                    id=None,
                    username=None,
                    first_name=None,
                    last_name=None,
                    email=None,
                    password=None,
                    phone=None,
                    user_status=None):
        """Does a PUT request to /user/{name}.

        This can only be done by the logged in user.

        Args:
            name (str): name that need to be deleted
            id (int, optional): The request form parameter.
            username (str, optional): The request form parameter.
            first_name (str, optional): The request form parameter.
            last_name (str, optional): The request form parameter.
            email (str, optional): The request form parameter.
            password (str, optional): The request form parameter.
            phone (str, optional): The request form parameter.
            user_status (int, optional): User Status

        Returns:
            void: 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('/user/{name}')
            .http_method(HttpMethodEnum.PUT)
            .template_param(Parameter()
                            .key('name')
                            .value(name)
                            .should_encode(True))
            .form_param(Parameter()
                        .key('id')
                        .value(id))
            .form_param(Parameter()
                        .key('username')
                        .value(username))
            .form_param(Parameter()
                        .key('firstName')
                        .value(first_name))
            .form_param(Parameter()
                        .key('lastName')
                        .value(last_name))
            .form_param(Parameter()
                        .key('email')
                        .value(email))
            .form_param(Parameter()
                        .key('password')
                        .value(password))
            .form_param(Parameter()
                        .key('phone')
                        .value(phone))
            .form_param(Parameter()
                        .key('userStatus')
                        .value(user_status))
            .header_param(Parameter()
                          .key('content-type')
                          .value('application/x-www-form-urlencoded'))
        ).execute()

    def delete_user(self,
                    name):
        """Does a DELETE request to /user/{name}.

        This can only be done by the logged in user.

        Args:
            name (str): The name that needs to be deleted

        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('/user/{name}')
            .http_method(HttpMethodEnum.DELETE)
            .template_param(Parameter()
                            .key('name')
                            .value(name)
                            .should_encode(True))
        ).execute()
