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

"""
paypalserversdk

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

from paypalserversdk.api_helper import APIHelper
from paypalserversdk.configuration import Server
from paypalserversdk.http.api_response import ApiResponse
from paypalserversdk.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 paypalserversdk.http.http_method_enum import HttpMethodEnum
from apimatic_core.authentication.multiple.single_auth import Single
from paypalserversdk.models.search_response import SearchResponse
from paypalserversdk.models.balances_response import BalancesResponse
from paypalserversdk.exceptions.search_error_exception import SearchErrorException
from paypalserversdk.exceptions.default_error_exception import DefaultErrorException


class TransactionSearchController(BaseController):

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

    def search_transactions(self,
                            options=dict()):
        """Does a GET request to /v1/reporting/transactions.

        Lists transactions. Specify one or more query parameters to filter the
        transaction that appear in the response. Notes: If you specify one or
        more optional query parameters, the ending_balance response field is
        empty. It takes a maximum of three hours for executed transactions to
        appear in the list transactions call. This call lists transaction for
        the previous three years.

        Args:
            options (dict, optional): Key-value pairs for any of the
                parameters to this API Endpoint. All parameters to the
                endpoint are supplied through the dictionary with their names
                being the key and their desired values being the value. A list
                of parameters that can be used are::

                    start_date -- str -- Filters the transactions in the
                        response by a start date and time, in [Internet date
                        and time
                        format](https://tools.ietf.org/html/rfc3339#section-5.6
                        ). Seconds are required. Fractional seconds are
                        optional.
                    end_date -- str -- Filters the transactions in the
                        response by an end date and time, in [Internet date
                        and time
                        format](https://tools.ietf.org/html/rfc3339#section-5.6
                        ). Seconds are required. Fractional seconds are
                        optional. The maximum supported range is 31 days.
                    transaction_id -- str -- Filters the transactions in the
                        response by a PayPal transaction ID. A valid
                        transaction ID is 17 characters long, except for an
                        order ID, which is 19 characters long. Note: A
                        transaction ID is not unique in the reporting system.
                        The response can list two transactions with the same
                        ID. One transaction can be balance affecting while the
                        other is non-balance affecting.
                    transaction_type -- str -- Filters the transactions in the
                        response by a PayPal transaction event code. See
                        [Transaction event
                        codes](/docs/integration/direct/transaction-search/tran
                        saction-event-codes/).
                    transaction_status -- str -- Filters the transactions in
                        the response by a PayPal transaction status code.
                        Value is: Status code Description D PayPal or merchant
                        rules denied the transaction. P The transaction is
                        pending. The transaction was created but waits for
                        another payment process to complete, such as an ACH
                        transaction, before the status changes to S. S The
                        transaction successfully completed without a denial
                        and after any pending statuses. V A successful
                        transaction was reversed and funds were refunded to
                        the original sender.
                    transaction_amount -- str -- Filters the transactions in
                        the response by a gross transaction amount range.
                        Specify the range as ` TO `, where ` ` is the lower
                        limit of the gross PayPal transaction amount and ` `
                        is the upper limit of the gross transaction amount.
                        Specify the amounts in lower denominations. For
                        example, to search for transactions from $5.00 to
                        $10.05, specify `[500 TO 1005]`. Note:The values must
                        be URL encoded.
                    transaction_currency -- str -- Filters the transactions in
                        the response by a [three-character ISO-4217 currency
                        code](/api/rest/reference/currency-codes/) for the
                        PayPal transaction currency.
                    payment_instrument_type -- str -- Filters the transactions
                        in the response by a payment instrument type. Value is
                        either: CREDITCARD. Returns a direct credit card
                        transaction with a corresponding value. DEBITCARD.
                        Returns a debit card transaction with a corresponding
                        value. If you omit this parameter, the API does not
                        apply this filter.
                    store_id -- str -- Filters the transactions in the
                        response by a store ID.
                    terminal_id -- str -- Filters the transactions in the
                        response by a terminal ID.
                    fields -- str -- Indicates which fields appear in the
                        response. Value is a single field or a comma-separated
                        list of fields. The transaction_info value returns
                        only the transaction details in the response. To
                        include all fields in the response, specify
                        fields=all. Valid fields are: transaction_info. The
                        transaction information. Includes the ID of the PayPal
                        account of the payee, the PayPal-generated transaction
                        ID, the PayPal-generated base ID, the PayPal reference
                        ID type, the transaction event code, the date and time
                        when the transaction was initiated and was last
                        updated, the transaction amounts including the PayPal
                        fee, any discounts, insurance, the transaction status,
                        and other information about the transaction.
                        payer_info. The payer information. Includes the PayPal
                        customer account ID and the payer's email address,
                        primary phone number, name, country code, address, and
                        whether the payer is verified or unverified.
                        shipping_info. The shipping information. Includes the
                        recipient's name, the shipping method for this order,
                        the shipping address for this order, and the secondary
                        address associated with this order. auction_info. The
                        auction information. Includes the name of the auction
                        site, the auction site URL, the ID of the customer who
                        makes the purchase in the auction, and the date and
                        time when the auction closes. cart_info. The cart
                        information. Includes an array of item details,
                        whether the item amount or the shipping amount already
                        includes tax, and the ID of the invoice for
                        PayPal-generated invoices. incentive_info. An array of
                        incentive detail objects. Each object includes the
                        incentive, such as a special offer or coupon, the
                        incentive amount, and the incentive program code that
                        identifies a merchant loyalty or incentive program.
                        store_info. The store information. Includes the ID of
                        the merchant store and the terminal ID for the
                        checkout stand in the merchant store.
                    balance_affecting_records_only -- str -- Indicates whether
                        the response includes only balance-impacting
                        transactions or all transactions. Value is either: Y.
                        The default. The response includes only balance
                        transactions. N. The response includes all
                        transactions.
                    page_size -- int -- The number of items to return in the
                        response. So, the combination of `page=1` and
                        `page_size=20` returns the first 20 items. The
                        combination of `page=2` and `page_size=20` returns the
                        next 20 items.
                    page -- int -- The zero-relative start index of the entire
                        list of items that are returned in the response. So,
                        the combination of `page=1` and `page_size=20` returns
                        the first 20 items.

        Returns:
            ApiResponse: An object with the response value as well as other
                useful information such as status codes and headers. A
                successful request returns the HTTP `200 OK` status code and a
                JSON response body that lists transactions .

        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('/v1/reporting/transactions')
            .http_method(HttpMethodEnum.GET)
            .query_param(Parameter()
                         .key('start_date')
                         .value(options.get('start_date', None)))
            .query_param(Parameter()
                         .key('end_date')
                         .value(options.get('end_date', None)))
            .query_param(Parameter()
                         .key('transaction_id')
                         .value(options.get('transaction_id', None)))
            .query_param(Parameter()
                         .key('transaction_type')
                         .value(options.get('transaction_type', None)))
            .query_param(Parameter()
                         .key('transaction_status')
                         .value(options.get('transaction_status', None)))
            .query_param(Parameter()
                         .key('transaction_amount')
                         .value(options.get('transaction_amount', None)))
            .query_param(Parameter()
                         .key('transaction_currency')
                         .value(options.get('transaction_currency', None)))
            .query_param(Parameter()
                         .key('payment_instrument_type')
                         .value(options.get('payment_instrument_type', None)))
            .query_param(Parameter()
                         .key('store_id')
                         .value(options.get('store_id', None)))
            .query_param(Parameter()
                         .key('terminal_id')
                         .value(options.get('terminal_id', None)))
            .query_param(Parameter()
                         .key('fields')
                         .value(options.get('fields', None)))
            .query_param(Parameter()
                         .key('balance_affecting_records_only')
                         .value(options.get('balance_affecting_records_only', None)))
            .query_param(Parameter()
                         .key('page_size')
                         .value(options.get('page_size', None)))
            .query_param(Parameter()
                         .key('page')
                         .value(options.get('page', None)))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .auth(Single('Oauth2'))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(SearchResponse.from_dictionary)
            .is_api_response(True)
            .local_error('default', 'The error response.', SearchErrorException)
        ).execute()

    def search_balances(self,
                        options=dict()):
        """Does a GET request to /v1/reporting/balances.

        List all balances. Specify date time to list balances for that time
        that appear in the response. Notes: It takes a maximum of three hours
        for balances to appear in the list balances call. This call lists
        balances upto the previous three years.

        Args:
            options (dict, optional): Key-value pairs for any of the
                parameters to this API Endpoint. All parameters to the
                endpoint are supplied through the dictionary with their names
                being the key and their desired values being the value. A list
                of parameters that can be used are::

                    as_of_time -- str -- List balances in the response at the
                        date time provided, will return the last refreshed
                        balance in the system when not provided.
                    currency_code -- str -- Filters the transactions in the
                        response by a [three-character ISO-4217 currency
                        code](/api/rest/reference/currency-codes/) for the
                        PayPal transaction currency.

        Returns:
            ApiResponse: An object with the response value as well as other
                useful information such as status codes and headers. A
                successful request returns the HTTP `200 OK` status code and a
                JSON response body that lists balances .

        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('/v1/reporting/balances')
            .http_method(HttpMethodEnum.GET)
            .query_param(Parameter()
                         .key('as_of_time')
                         .value(options.get('as_of_time', None)))
            .query_param(Parameter()
                         .key('currency_code')
                         .value(options.get('currency_code', None)))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .auth(Single('Oauth2'))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(BalancesResponse.from_dictionary)
            .is_api_response(True)
            .local_error('400', 'The request is not well-formed, is syntactically incorrect, or violates schema.', DefaultErrorException)
            .local_error('403', 'Authorization failed due to insufficient permissions.', DefaultErrorException)
            .local_error('500', 'An internal server error occurred.', DefaultErrorException)
            .local_error('default', 'The error response.', DefaultErrorException)
        ).execute()
