"""visaacceptancemergedspec.

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

# ruff: noqa: D410, E501, E101, D206
from apimatic_core.authentication.multiple.and_auth_group import (
    And,
)
from apimatic_core.authentication.multiple.single_auth import (
    Single,
)
from apimatic_core.request_builder import RequestBuilder
from apimatic_core.response_handler import ResponseHandler
from apimatic_core.types.parameter import Parameter

from visaacceptancemergedspec.api_helper import (
    APIHelper,
)
from visaacceptancemergedspec.apis.base_api import (
    BaseApi,
)
from visaacceptancemergedspec.configuration import (
    Server,
)
from visaacceptancemergedspec.exceptions.delete_customer_exception_1_exception import (
    DeleteCustomerException1Exception,
)
from visaacceptancemergedspec.exceptions.delete_customer_exception_21_exception import (
    DeleteCustomerException21Exception,
)
from visaacceptancemergedspec.exceptions.delete_customer_exception_31_exception import (
    DeleteCustomerException31Exception,
)
from visaacceptancemergedspec.exceptions.delete_customer_exception_41_exception import (
    DeleteCustomerException41Exception,
)
from visaacceptancemergedspec.exceptions.delete_customer_exception_61_exception import (
    DeleteCustomerException61Exception,
)
from visaacceptancemergedspec.exceptions.get_customer_exception_1_exception import (
    GetCustomerException1Exception,
)
from visaacceptancemergedspec.exceptions.get_customer_exception_21_exception import (
    GetCustomerException21Exception,
)
from visaacceptancemergedspec.exceptions.get_customer_exception_31_exception import (
    GetCustomerException31Exception,
)
from visaacceptancemergedspec.exceptions.get_customer_exception_41_exception import (
    GetCustomerException41Exception,
)
from visaacceptancemergedspec.exceptions.get_customer_exception_61_exception import (
    GetCustomerException61Exception,
)
from visaacceptancemergedspec.exceptions.patch_customer_exception_1_exception import (
    PatchCustomerException1Exception,
)
from visaacceptancemergedspec.exceptions.patch_customer_exception_21_exception import (
    PatchCustomerException21Exception,
)
from visaacceptancemergedspec.exceptions.patch_customer_exception_31_exception import (
    PatchCustomerException31Exception,
)
from visaacceptancemergedspec.exceptions.patch_customer_exception_41_exception import (
    PatchCustomerException41Exception,
)
from visaacceptancemergedspec.exceptions.patch_customer_exception_51_exception import (
    PatchCustomerException51Exception,
)
from visaacceptancemergedspec.exceptions.patch_customer_exception_71_exception import (
    PatchCustomerException71Exception,
)
from visaacceptancemergedspec.exceptions.post_customer_exception_1_exception import (
    PostCustomerException1Exception,
)
from visaacceptancemergedspec.exceptions.post_customer_exception_21_exception import (
    PostCustomerException21Exception,
)
from visaacceptancemergedspec.exceptions.post_customer_exception_31_exception import (
    PostCustomerException31Exception,
)
from visaacceptancemergedspec.exceptions.post_customer_exception_41_exception import (
    PostCustomerException41Exception,
)
from visaacceptancemergedspec.exceptions.post_customer_exception_51_exception import (
    PostCustomerException51Exception,
)
from visaacceptancemergedspec.http.http_method_enum import (
    HttpMethodEnum,
)
from visaacceptancemergedspec.models.get_customer_response import (
    GetCustomerResponse,
)
from visaacceptancemergedspec.models.patch_customer_response import (
    PatchCustomerResponse,
)
from visaacceptancemergedspec.models.tms_v_2_customers_response import (
    TmsV2CustomersResponse,
)


class CustomerApi(BaseApi):
    """A Controller to access Endpoints in the visaacceptancemergedspec API."""

    def __init__(self, config):
        """Initialize CustomerApi object."""
        super(CustomerApi, self).__init__(config)

    def post_customer(self,
                      body,
                      profile_id=None):
        """Perform a POST request to /tms/v2/customers.

        |  |  |  |
        | --- | --- | --- |
        |**Customers**<br>A Customer represents your tokenized customer
        information.<br>You should associate the Customer Id with the customer
        account on your systems.<br>A Customer can have one or more [Payment
        Instruments](#token-management_customer-payment-instrument_create-a-customer-p
        ayment-instrumentl) or [Shipping
        Addresses](#token-management_customer-shipping-address_create-a-customer-shipp
        ing-address) with one allocated as the Customers default.<br><br>**Creating a
        Customer**<br>It is recommended you [create a Customer via a Payment
        Authorization](#payments_payments_process-a-payment_samplerequests-dropdown_au
        thorization-with-token-create_authorization-with-customer-token-creation_livec
        onsole-tab-request-body), this can be for a zero amount.<br>The Customer will
        be created with a Payment Instrument and Shipping Address.<br>You can also
        [add additional Payment Instruments to a Customer via a Payment
        Authorization](#payments_payments_process-a-payment_samplerequests-dropdown_au
        thorization-with-token-create_authorization-create-default-payment-instrument-
        shipping-address-for-existing-customer_liveconsole-tab-request-body).<br>In
        Europe: You should perform Payer Authentication alongside the
        Authorization.|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|**Payment Network
        Tokens**<br>Network tokens perform better than regular card numbers and they
        are not necessarily invalidated when a cardholder loses their card, or it
        expires.<br>A Payment Network Token will be automatically created and used in
        future payments if you are enabled for the service.<br>A Payment Network
        Token can also be [provisioned for an existing Instrument
        Identifier](#token-management_instrument-identifier_enroll-an-instrument-ident
        ifier-for-payment-network-token).<br>For more information about Payment
        Network Tokens see the Developer Guide.<br><br>**Payments with
        Customers**<br>To perform a payment with the Customers default details
        specify the [Customer Id in the payments
        request](#payments_payments_process-a-payment_samplerequests-dropdown_authoriz
        ation-using-tokens_authorization-with-customer-token-id_liveconsole-tab-reques
        t-body).<br>To perform a payment with a particular Payment Instrument or
        Shipping Address <br>specify the [Payment Instrument or Shipping Address Ids
        in the payments
        request](#payments_payments_process-a-payment_samplerequests-dropdown_authoriz
        ation-using-tokens_authorization-with-customer-payment-instrument-and-shipping
        -address-token-id_liveconsole-tab-request-body).
        The availability of API features for a merchant may depend on the portfolio
        configuration and may need to be enabled at the portfolio level before they
        can be added to merchant accounts.

        Args:
            body (PostCustomerRequest): The request body parameter.
            profile_id (str, optional): The Id of a profile containing user specific
                TMS configuration.

        Returns:
            ApiResponse: An object with the response value as well as other useful
                information such as status codes and headers. A new Customer has been
                created.

        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("/tms/v2/customers")
            .http_method(HttpMethodEnum.POST)
            .header_param(Parameter()
                .key("Content-Type")
                .value("application/json;charset=utf-8"))
            .body_param(Parameter()
                .value(body)
                .is_required(True))
            .header_param(Parameter()
                .key("profile-id")
                .value(profile_id))
            .header_param(Parameter()
                .key("accept")
                .value("application/json"))
            .body_serializer(APIHelper.json_serialize)
            .auth(And(Single("BearerAuth"), Single("Accept"))),
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(TmsV2CustomersResponse.from_dictionary)
            .is_api_response(True)
            .local_error("400",
                "Bad Request: e.g. A required header value could be missing.",
                PostCustomerException1Exception)
            .local_error("403",
                "Forbidden: e.g. The profile might not have permission to perform the"
                " operation.",
                PostCustomerException21Exception)
            .local_error("409",
                "Conflict. The token is linked to a Payment Instrument.",
                PostCustomerException31Exception)
            .local_error("424",
                "Failed Dependency: e.g. The profile represented by the profile-id ma"
                "y not exist or the profile-id was entered incorrectly.",
                PostCustomerException41Exception)
            .local_error("500", "Unexpected error.", PostCustomerException51Exception),
        ).execute()

    def get_customer(self,
                     customer_id,
                     profile_id=None):
        """Perform a GET request to /tms/v2/customers/{customerId}.

        |  |  |  |
        | --- | --- | --- |
        |**Customers**<br>A Customer represents your tokenized customer
        information.<br>You should associate the Customer Id with the customer
        account on your systems.<br>A Customer can have one or more [Payment
        Instruments](#token-management_customer-payment-instrument_create-a-customer-p
        ayment-instrumentl) or [Shipping
        Addresses](#token-management_customer-shipping-address_create-a-customer-shipp
        ing-address) with one allocated as the Customers default.<br><br>**Retrieving
        a Customer**<br>When your customer signs into their account, your system can
        use this API to retrieve the Customers default Payment Instrument and
        Shipping Address.<br>**Note: the actual card data will be masked.**<br>If
        your customer wants to see other available Payment Instruments, your system
        can [retrieve all Payment
        Instruments](#token-management_customer-payment-instrument_list-payment-instru
        ments-for-a-customer) associated with the Customer.<br>The same applies to
        [Shipping
        Addresses](#token-management_customer-shipping-address_list-shipping-addresses
        -for-a-customer).|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|**Payment Network
        Tokens**<br>Network tokens perform better than regular card numbers and they
        are not necessarily invalidated when a cardholder loses their card, or it
        expires.<br>A Payment Network Token will be automatically created and used in
        future payments if you are enabled for the service.<br>A Payment Network
        Token can also be [provisioned for an existing Instrument
        Identifier](#token-management_instrument-identifier_enroll-an-instrument-ident
        ifier-for-payment-network-token).<br>For more information about Payment
        Network Tokens see the Developer Guide.<br><br>**Payments with
        Customers**<br>To perform a payment with the Customers default details
        specify the [Customer Id in the payments
        request](#payments_payments_process-a-payment_samplerequests-dropdown_authoriz
        ation-using-tokens_authorization-with-customer-token-id_liveconsole-tab-reques
        t-body).<br>To perform a payment with a particular Payment Instrument or
        Shipping Address <br>specify the [Payment Instrument or Shipping Address Ids
        in the payments
        request](#payments_payments_process-a-payment_samplerequests-dropdown_authoriz
        ation-using-tokens_authorization-with-customer-payment-instrument-and-shipping
        -address-token-id_liveconsole-tab-request-body).

        Args:
            customer_id (str): The Id of a Customer.
            profile_id (str, optional): The Id of a profile containing user specific
                TMS configuration.

        Returns:
            ApiResponse: An object with the response value as well as other useful
                information such as status codes and headers. Returns an existing
                Customer associated with the supplied Id.

        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("/tms/v2/customers/{customerId}")
            .http_method(HttpMethodEnum.GET)
            .template_param(Parameter()
                .key("customerId")
                .value(customer_id)
                .is_required(True)
                .should_encode(True))
            .header_param(Parameter()
                .key("profile-id")
                .value(profile_id))
            .header_param(Parameter()
                .key("accept")
                .value("application/json"))
            .auth(And(Single("BearerAuth"), Single("Accept"))),
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(GetCustomerResponse.from_dictionary)
            .is_api_response(True)
            .local_error("400",
                "Bad Request: e.g. A required header value could be missing.",
                GetCustomerException1Exception)
            .local_error("403",
                "Forbidden: e.g. The profile might not have permission to perform the"
                " operation.",
                GetCustomerException21Exception)
            .local_error("404",
                "Token Not Found. The Id may not exist or was entered incorrectly.",
                GetCustomerException31Exception)
            .local_error("410",
                "Token Not Available. The token has been deleted.",
                GetCustomerException41Exception)
            .local_error("424",
                "Failed Dependency: e.g. The profile represented by the profile-id ma"
                "y not exist or the profile-id was entered incorrectly.",
                GetCustomerException31Exception)
            .local_error("500", "Unexpected error.", GetCustomerException61Exception),
        ).execute()

    def patch_customer(self,
                       customer_id,
                       body,
                       profile_id=None,
                       if_match=None):
        """Perform a PATCH request to /tms/v2/customers/{customerId}.

        |  |  |  |
        | --- | --- | --- |
        |**Customers**<br>A Customer represents your tokenized customer
        information.<br>You should associate the Customer Id with the customer
        account on your systems.<br>A Customer can have one or more [Payment
        Instruments](#token-management_customer-payment-instrument_create-a-customer-p
        ayment-instrumentl) or [Shipping
        Addresses](#token-management_customer-shipping-address_create-a-customer-shipp
        ing-address) with one allocated as the Customers
        default.|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|**Updating a Customer**<br>Your
        system can use this API to update a Customers details including selecting a
        [default Payment
        Instrument](#token-management_customer_update-a-customer_samplerequests-dropdo
        wn_update-customers-default-payment-instrument_liveconsole-tab-request-body)
        or [default Shipping
        Address](#token-management_customer_update-a-customer_samplerequests-dropdown_
        update-customers-default-shipping-address_liveconsole-tab-request-body) for
        use in payments.<br>Note: Updating a Customers [Payment
        Instrument](#token-management_customer-payment-instrument_update-a-customer-pa
        yment-instrument) or [Shipping
        Address](#token-management_customer-shipping-address_update-a-customer-shippin
        g-address) details is performed using their own dedicated API resources.

        Args:
            customer_id (str): The Id of a Customer.
            body (PatchCustomerRequest): The request body parameter.
            profile_id (str, optional): The Id of a profile containing user specific
                TMS configuration.
            if_match (str, optional): Contains an ETag value from a GET request to
                make the request conditional.

        Returns:
            ApiResponse: An object with the response value as well as other useful
                information such as status codes and headers. Returns an existing
                Customer associated with the supplied Id.

        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("/tms/v2/customers/{customerId}")
            .http_method(HttpMethodEnum.PATCH)
            .template_param(Parameter()
                .key("customerId")
                .value(customer_id)
                .is_required(True)
                .should_encode(True))
            .header_param(Parameter()
                .key("Content-Type")
                .value("application/json;charset=utf-8"))
            .body_param(Parameter()
                .value(body)
                .is_required(True))
            .header_param(Parameter()
                .key("profile-id")
                .value(profile_id))
            .header_param(Parameter()
                .key("if-match")
                .value(if_match))
            .header_param(Parameter()
                .key("accept")
                .value("application/json"))
            .body_serializer(APIHelper.json_serialize)
            .auth(And(Single("BearerAuth"), Single("Accept"))),
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(PatchCustomerResponse.from_dictionary)
            .is_api_response(True)
            .local_error("400",
                "Bad Request: e.g. A required header value could be missing.",
                PatchCustomerException1Exception)
            .local_error("403",
                "Forbidden: e.g. The profile might not have permission to perform the"
                " operation.",
                PatchCustomerException21Exception)
            .local_error("404",
                "Token Not Found. The Id may not exist or was entered incorrectly.",
                PatchCustomerException31Exception)
            .local_error("410",
                "Token Not Available. The token has been deleted.",
                PatchCustomerException41Exception)
            .local_error("412",
                "Precondition Failed: The If-Match request header value does not matc"
                "h the current resources ETag",
                PatchCustomerException51Exception)
            .local_error("424",
                "Failed Dependency: e.g. The profile represented by the profile-id ma"
                "y not exist or the profile-id was entered incorrectly.",
                PatchCustomerException31Exception)
            .local_error("500",
                "Unexpected error.",
                PatchCustomerException71Exception),
        ).execute()

    def delete_customer(self,
                        customer_id,
                        profile_id=None):
        """Perform a DELETE request to /tms/v2/customers/{customerId}.

        |  |  |  |
        | --- | --- | --- |
        |**Customers**<br>A Customer represents your tokenized customer
        information.<br>You should associate the Customer Id with the customer
        account on your systems.<br>A Customer can have one or more [Payment
        Instruments](#token-management_customer-payment-instrument_create-a-customer-p
        ayment-instrumentl) or [Shipping
        Addresses](#token-management_customer-shipping-address_create-a-customer-shipp
        ing-address) with one allocated as the Customers
        default.|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|**Deleting a Customer**<br>Your
        system can use this API to delete a complete Customer.<br>When a Customer is
        deleted all associated Payment Instruments & Shipping Addresses are
        deleted.<br>Any Instrument Identifiers representing the card number will also
        be deleted if they are not associated with any other Payment
        Instruments.<br>Note: Individual [Payment
        Instruments](#token-management_customer-payment-instrument_delete-a-customer-p
        ayment-instrument) or [Shipping
        Addresses](#token-management_customer-shipping-address_delete-a-customer-shipp
        ing-address) can be deleted via their own dedicated API resources.

        Args:
            customer_id (str): The Id of a Customer.
            profile_id (str, optional): The Id of a profile containing user specific
                TMS configuration.

        Returns:
            ApiResponse: An object with the response value as well as other useful
                information such as status codes and headers. The request is
                fulfilled but does not need to return a body

        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("/tms/v2/customers/{customerId}")
            .http_method(HttpMethodEnum.DELETE)
            .template_param(Parameter()
                .key("customerId")
                .value(customer_id)
                .is_required(True)
                .should_encode(True))
            .header_param(Parameter()
                .key("profile-id")
                .value(profile_id))
            .header_param(Parameter()
                .key("accept")
                .value("application/json"))
            .auth(And(Single("BearerAuth"), Single("Accept"))),
        ).response(
            ResponseHandler()
            .is_api_response(True)
            .local_error("400",
                "Bad Request: e.g. A required header value could be missing.",
                DeleteCustomerException1Exception)
            .local_error("403",
                "Forbidden: e.g. The profile might not have permission to perform the"
                " operation.",
                DeleteCustomerException21Exception)
            .local_error("404",
                "Token Not Found. The Id may not exist or was entered incorrectly.",
                DeleteCustomerException31Exception)
            .local_error("410",
                "Token Not Available. The token has been deleted.",
                DeleteCustomerException41Exception)
            .local_error("424",
                "Failed Dependency: e.g. The profile represented by the profile-id ma"
                "y not exist or the profile-id was entered incorrectly.",
                DeleteCustomerException31Exception)
            .local_error("500",
                "Unexpected error.",
                DeleteCustomerException61Exception),
        ).execute()
