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

"""
pqapiv2

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

from pqapiv2.api_helper import APIHelper
from pqapiv2.configuration import Server
from pqapiv2.controllers.base_controller import BaseController
from pqapiv2.models.user_response import UserResponse
from pqapiv2.models.user_collection_response import UserCollectionResponse
from pqapiv2.models.identity_verification_collection_response import IdentityVerificationCollectionResponse
from pqapiv2.models.identity_verification_response import IdentityVerificationResponse


class UsersController(BaseController):

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

    def update_user(self,
                    user_token,
                    x_my_pay_quicker_version,
                    body=None):
        """Does a PUT request to /users/{user-token}.

        Update a user object (change email, address change, etc.) using a user
        token.

        Args:
            user_token (string): Auto-generated unique identifier representing
                a user, prefixed with <i>user-</i>.
            x_my_pay_quicker_version (string): Date-based API Version
                specified in the header <i>required</i> on all calls.
            body (UserBase, optional): TODO: type description here.

        Returns:
            UserResponse: Response from the API. Reference

        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 = '/users/{user-token}'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'user-token': {'value': user_token, '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',
            'X-MyPayQuicker-Version': x_my_pay_quicker_version,
            'Content-Type': 'application/json'
        }

        # 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, UserResponse.from_dictionary)

        return decoded

    def retrieve_user(self,
                      user_token,
                      x_my_pay_quicker_version):
        """Does a GET request to /users/{user-token}.

        Retrieve a single user record by user token.

        Args:
            user_token (string): Auto-generated unique identifier representing
                a user, prefixed with <i>user-</i>.
            x_my_pay_quicker_version (string): Date-based API Version
                specified in the header <i>required</i> on all calls.

        Returns:
            UserResponse: Response from the API. OK

        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 = '/users/{user-token}'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'user-token': {'value': user_token, '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',
            'X-MyPayQuicker-Version': x_my_pay_quicker_version
        }

        # 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, UserResponse.from_dictionary)

        return decoded

    def list_users(self,
                   x_my_pay_quicker_version,
                   page=None,
                   page_size=20,
                   filter=None,
                   sort=None,
                   language=None):
        """Does a GET request to /users.

        Retrieve a list of all users that supports filtering, sorting, and
        pagination through existing mechanisms.

        Args:
            x_my_pay_quicker_version (string): Date-based API Version
                specified in the header <i>required</i> on all calls.
            page (int, optional): Page number of specific page to return
            page_size (int, optional): Number of items to be displayed per
                page
            filter (string, optional): Filter request results by specific
                criteria.
            sort (string, optional): Sort request results by specific
                attribute.
            language (LanguageTypesEnum, optional): Filter results by language
                type.

        Returns:
            UserCollectionResponse: 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 = '/users'
        _query_builder = self.config.get_base_uri()
        _query_builder += _url_path
        _query_parameters = {
            'page': page,
            'pageSize': page_size,
            'filter': filter,
            'sort': sort,
            'language': language
        }
        _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',
            'X-MyPayQuicker-Version': x_my_pay_quicker_version
        }

        # 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, UserCollectionResponse.from_dictionary)

        return decoded

    def create_user(self,
                    x_my_pay_quicker_version,
                    body):
        """Does a POST request to /users.

        Create a new user. Payload contains both required and optional fields
        for user- and company-based users, allowing for the creation of a
        corporate/partnership/dba (i.e., Grubhub model) user along with a
        standard end user (i.e., <i>Payee</i>). The type of the user
        (<i>Business</i> vs. <i>User</i>) and type of business
        (<i>Corporation</i> vs. <i>Partnership</i>) provide context that
        impacts KYC etc.

        Args:
            x_my_pay_quicker_version (string): Date-based API Version
                specified in the header <i>required</i> on all calls.
            body (UserBase): Body details of the request

        Returns:
            UserResponse: Response from the API. Previously created user
                response

        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 = '/users'
        _query_builder = self.config.get_base_uri()
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            'accept': 'application/json',
            'X-MyPayQuicker-Version': x_my_pay_quicker_version,
            'Content-Type': 'application/json'
        }

        # 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, UserResponse.from_dictionary)

        return decoded

    def list_user_idv_checks(self,
                             user_token,
                             x_my_pay_quicker_version):
        """Does a GET request to /users/{user-token}/idv-checks.

        Retrieve a list of IDV checks by user token that supports filtering,
        sorting, and pagination through existing mechanisms.

        Args:
            user_token (string): Auto-generated unique identifier representing
                a user, prefixed with <i>user-</i>.
            x_my_pay_quicker_version (string): Date-based API Version
                specified in the header <i>required</i> on all calls.

        Returns:
            IdentityVerificationCollectionResponse: Response from the API. OK

        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 = '/users/{user-token}/idv-checks'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'user-token': {'value': user_token, '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',
            'X-MyPayQuicker-Version': x_my_pay_quicker_version
        }

        # 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, IdentityVerificationCollectionResponse.from_dictionary)

        return decoded

    def retrieve_user_idv_check(self,
                                user_token,
                                idvc_token,
                                x_my_pay_quicker_version):
        """Does a GET request to /users/{user-token}/idv-checks/{idvc-token}.

        Retrieve a list of all IDV check by IDVC token that supports
        filtering, sorting, and pagination through existing mechanisms.

        Args:
            user_token (string): Auto-generated unique identifier representing
                a user, prefixed with <i>user-</i>.
            idvc_token (string): Auto-generated unique identifier representing
                a user IDV check, prefixed with <i>idvc-</i>.
            x_my_pay_quicker_version (string): Date-based API Version
                specified in the header <i>required</i> on all calls.

        Returns:
            IdentityVerificationResponse: Response from the API. OK

        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 = '/users/{user-token}/idv-checks/{idvc-token}'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'user-token': {'value': user_token, 'encode': True},
            'idvc-token': {'value': idvc_token, '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',
            'X-MyPayQuicker-Version': x_my_pay_quicker_version
        }

        # 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, IdentityVerificationResponse.from_dictionary)

        return decoded

    def list_user_events(self,
                         user_token):
        """Does a GET request to /users/{user-token}/events.

        Retrieve a list of all user events that supports filtering, sorting,
        and pagination through existing mechanisms.

        Args:
            user_token (string): Auto-generated unique identifier representing
                a user, prefixed with <i>user-</i>.

        Returns:
            void: Response from the API. OK

        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 = '/users/{user-token}/events'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'user-token': {'value': user_token, '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.get(_query_url)
        _response = self.execute_request(_request)
        self.validate_response(_response)

    def retrieve_user_event(self,
                            user_token,
                            evnt_token):
        """Does a GET request to /users/{user-token}/events/{evnt-token}.

        Retrieve a single user event

        Args:
            user_token (string): Auto-generated unique identifier representing
                a user, prefixed with <i>user-</i>.
            evnt_token (string): Auto-generated unique identifier representing
                an event, prefixed with <i>evnt-</i>.

        Returns:
            void: Response from the API. OK

        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 = '/users/{user-token}/events/{evnt-token}'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'user-token': {'value': user_token, 'encode': True},
            'evnt-token': {'value': evnt_token, '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.get(_query_url)
        _response = self.execute_request(_request)
        self.validate_response(_response)

    def accept_program_agreement(self,
                                 user_token,
                                 agmt_token):
        """Does a POST request to /users/{user-token}/agreements/{agmt-token}.

        Accept a single program agreement

        Args:
            user_token (string): Auto-generated unique identifier representing
                a user, prefixed with <i>user-</i>.
            agmt_token (string): Auto-generated unique identifier representing
                a program agreement, prefixed with <i>agmt-</i>.

        Returns:
            void: Response from the API. OK

        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 = '/users/{user-token}/agreements/{agmt-token}'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'user-token': {'value': user_token, 'encode': True},
            'agmt-token': {'value': agmt_token, '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.post(_query_url)
        _response = self.execute_request(_request)
        self.validate_response(_response)

    def list_accepted_program_agreements(self,
                                         user_token):
        """Does a GET request to /users/{user-token}/agreements.

        Retrieve a list of all accepted program agreements that supports
        filtering, sorting, and pagination through existing mechanisms.

        Args:
            user_token (string): Auto-generated unique identifier representing
                a user, prefixed with <i>user-</i>.

        Returns:
            void: Response from the API. OK

        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 = '/users/{user-token}/agreements'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'user-token': {'value': user_token, '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.get(_query_url)
        _response = self.execute_request(_request)
        self.validate_response(_response)
