# coding: utf-8

"""
    CardPay REST API

    Welcome to the CardPay REST API. The CardPay API uses HTTP verbs and a [REST](https://en.wikipedia.org/wiki/Representational_state_transfer) resources endpoint structure (see more info about REST). Request and response payloads are formatted as JSON. Merchant uses API to create payments, refunds, payouts or recurrings, check or update transaction status and get information about created transactions. In API authentication process based on [OAuth 2.0](https://oauth.net/2/) standard. For recent changes see changelog section.  # noqa: E501

    OpenAPI spec version: 3.0
    
    Generated by: https://github.com/swagger-api/swagger-codegen.git
"""


from __future__ import absolute_import

import re  # noqa: F401

# python 2 and python 3 compatibility library
import six

from cardpay.api_client import ApiClient


class RecurringsInstallmentsApi(object):
    """NOTE: This class is auto generated by the swagger code generator program.

    Do not edit the class manually.
    Ref: https://github.com/swagger-api/swagger-codegen
    """

    def __init__(self, api_client=None):
        if api_client is None:
            api_client = ApiClient()
        self.api_client = api_client

    def calculate_schedule(self, currency, request_id, **kwargs):  # noqa: E501
        """Get calculation of installment payment options  # noqa: E501

        :param str currency: [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) currency code (required)
        :param str request_id: Request ID (required)
        :param float total_amount: Total amount of subscription to be calculated to options; can have dot as a decimal separator.
        :return: ScheduleOptionsResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs["_return_http_data_only"] = True

        (data) = self.calculate_schedule_with_http_info(
            currency, request_id, **kwargs
        )  # noqa: E501
        return data

    def calculate_schedule_with_http_info(
        self, currency, request_id, **kwargs
    ):  # noqa: E501
        """Get calculation of installment payment options  # noqa: E501

        :param str currency: [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) currency code (required)
        :param str request_id: Request ID (required)
        :param float total_amount: Total amount of subscription to be calculated to options; can have dot as a decimal separator.
        :return: ScheduleOptionsResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ["currency", "request_id", "total_amount"]  # noqa: E501
        all_params.append("_return_http_data_only")
        all_params.append("_preload_content")
        all_params.append("_request_timeout")

        params = locals()
        for key, val in six.iteritems(params["kwargs"]):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method calculate_schedule" % key
                )
            params[key] = val
        del params["kwargs"]
        # verify the required parameter 'currency' is set
        if "currency" not in params or params["currency"] is None:
            raise ValueError(
                "Missing the required parameter `currency` when calling `calculate_schedule`"
            )  # noqa: E501
        # verify the required parameter 'request_id' is set
        if "request_id" not in params or params["request_id"] is None:
            raise ValueError(
                "Missing the required parameter `request_id` when calling `calculate_schedule`"
            )  # noqa: E501

        if "request_id" in params and len(params["request_id"]) > 50:
            raise ValueError(
                "Invalid value for parameter `request_id` when calling `calculate_schedule`, length must be less than or equal to `50`"
            )  # noqa: E501
        if "request_id" in params and len(params["request_id"]) < 0:
            raise ValueError(
                "Invalid value for parameter `request_id` when calling `calculate_schedule`, length must be greater than or equal to `0`"
            )  # noqa: E501
        collection_formats = {}

        path_params = {}

        query_params = []
        if "currency" in params:
            query_params.append(("currency", params["currency"]))  # noqa: E501
        if "request_id" in params:
            query_params.append(("request_id", params["request_id"]))  # noqa: E501
        if "total_amount" in params:
            query_params.append(("totalAmount", params["total_amount"]))  # noqa: E501

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        # HTTP header `Accept`
        header_params["Accept"] = self.api_client.select_header_accept(
            ["application/json"]
        )  # noqa: E501

        return self.api_client.call_api(
            "/api/installments/options_calculator",
            "GET",
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type="ScheduleOptionsResponse",  # noqa: E501
            _return_http_data_only=params.get("_return_http_data_only"),
            _preload_content=params.get("_preload_content", True),
            _request_timeout=params.get("_request_timeout"),
            collection_formats=collection_formats,
        )

    def create_installment(self, subscription_request, **kwargs):  # noqa: E501
        """Create installment  # noqa: E501

        :param InstallmentSubscriptionRequest subscription_request: subscriptionRequest (required)
        :return: RecurringGatewayCreationResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs["_return_http_data_only"] = True

        (data) = self.create_installment_with_http_info(
            subscription_request, **kwargs
        )  # noqa: E501
        return data

    def create_installment_with_http_info(
        self, subscription_request, **kwargs
    ):  # noqa: E501
        """Create installment  # noqa: E501

        :param InstallmentSubscriptionRequest subscription_request: subscriptionRequest (required)
        :return: RecurringGatewayCreationResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ["subscription_request"]  # noqa: E501
        all_params.append("_return_http_data_only")
        all_params.append("_preload_content")
        all_params.append("_request_timeout")

        params = locals()
        for key, val in six.iteritems(params["kwargs"]):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method create_installment" % key
                )
            params[key] = val
        del params["kwargs"]
        # verify the required parameter 'subscription_request' is set
        if (
            "subscription_request" not in params
            or params["subscription_request"] is None
        ):
            raise ValueError(
                "Missing the required parameter `subscription_request` when calling `create_installment`"
            )  # noqa: E501

        collection_formats = {}

        path_params = {}

        query_params = []

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        if "subscription_request" in params:
            body_params = params["subscription_request"]
        # HTTP header `Accept`
        header_params["Accept"] = self.api_client.select_header_accept(
            ["application/json"]
        )  # noqa: E501
        # HTTP header `Content-Type`
        header_params[
            "Content-Type"
        ] = self.api_client.select_header_content_type(  # noqa: E501
            ["application/json"]
        )  # noqa: E501

        return self.api_client.call_api(
            "/api/installments",
            "POST",
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type="RecurringGatewayCreationResponse",  # noqa: E501
            _return_http_data_only=params.get("_return_http_data_only"),
            _preload_content=params.get("_preload_content", True),
            _request_timeout=params.get("_request_timeout"),
            collection_formats=collection_formats,
        )

    def get_installment_payment(self, recurring_id, **kwargs):  # noqa: E501
        """Get installment payment  # noqa: E501

        :param str recurring_id: Recurring ID (required)
        :return: RecurringResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs["_return_http_data_only"] = True

        (data) = self.get_installment_payment_with_http_info(
            recurring_id, **kwargs
        )  # noqa: E501
        return data

    def get_installment_payment_with_http_info(
        self, recurring_id, **kwargs
    ):  # noqa: E501
        """Get installment payment  # noqa: E501

        :param str recurring_id: Recurring ID (required)
        :return: RecurringResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ["recurring_id"]  # noqa: E501
        all_params.append("_return_http_data_only")
        all_params.append("_preload_content")
        all_params.append("_request_timeout")

        params = locals()
        for key, val in six.iteritems(params["kwargs"]):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method get_installment_payment" % key
                )
            params[key] = val
        del params["kwargs"]
        # verify the required parameter 'recurring_id' is set
        if "recurring_id" not in params or params["recurring_id"] is None:
            raise ValueError(
                "Missing the required parameter `recurring_id` when calling `get_installment_payment`"
            )  # noqa: E501

        collection_formats = {}

        path_params = {}
        if "recurring_id" in params:
            path_params["recurringId"] = params["recurring_id"]  # noqa: E501

        query_params = []

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        # HTTP header `Accept`
        header_params["Accept"] = self.api_client.select_header_accept(
            ["application/json"]
        )  # noqa: E501

        return self.api_client.call_api(
            "/api/installments/{recurringId}",
            "GET",
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type="RecurringResponse",  # noqa: E501
            _return_http_data_only=params.get("_return_http_data_only"),
            _preload_content=params.get("_preload_content", True),
            _request_timeout=params.get("_request_timeout"),
            collection_formats=collection_formats,
        )

    def get_installment_payments(self, request_id, **kwargs):  # noqa: E501
        """Get installment payments  # noqa: E501

        :param str request_id: Request ID (required)
        :param str currency: [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) currency code of transactions currency
        :param datetime end_time: Date and time up to milliseconds (in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format) when requested period ends (not inclusive), UTC time, must be less than 7 days after 'start_time', default is current time (format: yyyy-MM-dd'T'HH:mm:ss'Z')
        :param int max_count: Limit number of returned transactions (must be less than 10000, default is 1000)
        :param str merchant_order_id: Merchant order number from the merchant system
        :param str payment_method: Used payment method type name from payment methods list
        :param list[str] recurring_types:
        :param str sort_order: Sort based on order of results. `asc` for ascending order or `desc` for descending order (default value)
        :param datetime start_time: Date and time up to milliseconds (in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format) when requested period starts (inclusive), UTC time, default is 24 hours before 'end_time' (format: yyyy-MM-dd'T'HH:mm:ss'Z')
        :param str type: Filter recurring payments by certain type (applicable to /api/recurrings endpoint only): `SCHEDULED` for scheduled recurring payments `ONECLICK` for one-click payments `INSTALLMENT` for installment payments
        :return: RecurringsList
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs["_return_http_data_only"] = True

        (data) = self.get_installment_payments_with_http_info(
            request_id, **kwargs
        )  # noqa: E501
        return data

    def get_installment_payments_with_http_info(
        self, request_id, **kwargs
    ):  # noqa: E501
        """Get installment payments  # noqa: E501

        :param str request_id: Request ID (required)
        :param str currency: [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) currency code of transactions currency
        :param datetime end_time: Date and time up to milliseconds (in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format) when requested period ends (not inclusive), UTC time, must be less than 7 days after 'start_time', default is current time (format: yyyy-MM-dd'T'HH:mm:ss'Z')
        :param int max_count: Limit number of returned transactions (must be less than 10000, default is 1000)
        :param str merchant_order_id: Merchant order number from the merchant system
        :param str payment_method: Used payment method type name from payment methods list
        :param list[str] recurring_types:
        :param str sort_order: Sort based on order of results. `asc` for ascending order or `desc` for descending order (default value)
        :param datetime start_time: Date and time up to milliseconds (in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format) when requested period starts (inclusive), UTC time, default is 24 hours before 'end_time' (format: yyyy-MM-dd'T'HH:mm:ss'Z')
        :param str type: Filter recurring payments by certain type (applicable to /api/recurrings endpoint only): `SCHEDULED` for scheduled recurring payments `ONECLICK` for one-click payments `INSTALLMENT` for installment payments
        :return: RecurringsList
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = [
            "request_id",
            "currency",
            "end_time",
            "max_count",
            "merchant_order_id",
            "payment_method",
            "recurring_types",
            "sort_order",
            "start_time",
            "type",
        ]  # noqa: E501
        all_params.append("_return_http_data_only")
        all_params.append("_preload_content")
        all_params.append("_request_timeout")

        params = locals()
        for key, val in six.iteritems(params["kwargs"]):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method get_installment_payments" % key
                )
            params[key] = val
        del params["kwargs"]
        # verify the required parameter 'request_id' is set
        if "request_id" not in params or params["request_id"] is None:
            raise ValueError(
                "Missing the required parameter `request_id` when calling `get_installment_payments`"
            )  # noqa: E501

        if "request_id" in params and len(params["request_id"]) > 50:
            raise ValueError(
                "Invalid value for parameter `request_id` when calling `get_installment_payments`, length must be less than or equal to `50`"
            )  # noqa: E501
        if "request_id" in params and len(params["request_id"]) < 0:
            raise ValueError(
                "Invalid value for parameter `request_id` when calling `get_installment_payments`, length must be greater than or equal to `0`"
            )  # noqa: E501
        if "max_count" in params and params["max_count"] > 10000:  # noqa: E501
            raise ValueError(
                "Invalid value for parameter `max_count` when calling `get_installment_payments`, must be a value less than or equal to `10000`"
            )  # noqa: E501
        if "merchant_order_id" in params and len(params["merchant_order_id"]) > 50:
            raise ValueError(
                "Invalid value for parameter `merchant_order_id` when calling `get_installment_payments`, length must be less than or equal to `50`"
            )  # noqa: E501
        if "merchant_order_id" in params and len(params["merchant_order_id"]) < 0:
            raise ValueError(
                "Invalid value for parameter `merchant_order_id` when calling `get_installment_payments`, length must be greater than or equal to `0`"
            )  # noqa: E501
        if "payment_method" in params and len(params["payment_method"]) > 100:
            raise ValueError(
                "Invalid value for parameter `payment_method` when calling `get_installment_payments`, length must be less than or equal to `100`"
            )  # noqa: E501
        if "payment_method" in params and len(params["payment_method"]) < 0:
            raise ValueError(
                "Invalid value for parameter `payment_method` when calling `get_installment_payments`, length must be greater than or equal to `0`"
            )  # noqa: E501
        if "sort_order" in params and not re.search(
            r"asc|desc", params["sort_order"]
        ):  # noqa: E501
            raise ValueError(
                "Invalid value for parameter `sort_order` when calling `get_installment_payments`, must conform to the pattern `/asc|desc/`"
            )  # noqa: E501
        collection_formats = {}

        path_params = {}

        query_params = []
        if "currency" in params:
            query_params.append(("currency", params["currency"]))  # noqa: E501
        if "end_time" in params:
            query_params.append(("end_time", params["end_time"]))  # noqa: E501
        if "max_count" in params:
            query_params.append(("max_count", params["max_count"]))  # noqa: E501
        if "merchant_order_id" in params:
            query_params.append(
                ("merchant_order_id", params["merchant_order_id"])
            )  # noqa: E501
        if "payment_method" in params:
            query_params.append(
                ("payment_method", params["payment_method"])
            )  # noqa: E501
        if "recurring_types" in params:
            query_params.append(
                ("recurring_types", params["recurring_types"])
            )  # noqa: E501
            collection_formats["recurring_types"] = "multi"  # noqa: E501
        if "request_id" in params:
            query_params.append(("request_id", params["request_id"]))  # noqa: E501
        if "sort_order" in params:
            query_params.append(("sort_order", params["sort_order"]))  # noqa: E501
        if "start_time" in params:
            query_params.append(("start_time", params["start_time"]))  # noqa: E501
        if "type" in params:
            query_params.append(("type", params["type"]))  # noqa: E501

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        # HTTP header `Accept`
        header_params["Accept"] = self.api_client.select_header_accept(
            ["application/json"]
        )  # noqa: E501

        return self.api_client.call_api(
            "/api/installments",
            "GET",
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type="RecurringsList",  # noqa: E501
            _return_http_data_only=params.get("_return_http_data_only"),
            _preload_content=params.get("_preload_content", True),
            _request_timeout=params.get("_request_timeout"),
            collection_formats=collection_formats,
        )

    def update_installment_payment(
        self, recurring_id, recurring_patch_request, **kwargs
    ):  # noqa: E501
        """Update installment payment  # noqa: E501

        :param str recurring_id: Recurring ID (required)
        :param RecurringPatchRequest recurring_patch_request: Recurring patch request (required)
        :return: RecurringResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs["_return_http_data_only"] = True

        (data) = self.update_installment_payment_with_http_info(
            recurring_id, recurring_patch_request, **kwargs
        )  # noqa: E501
        return data

    def update_installment_payment_with_http_info(
        self, recurring_id, recurring_patch_request, **kwargs
    ):  # noqa: E501
        """Update installment payment  # noqa: E501

        :param str recurring_id: Recurring ID (required)
        :param RecurringPatchRequest recurring_patch_request: Recurring patch request (required)
        :return: RecurringResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ["recurring_id", "recurring_patch_request"]  # noqa: E501
        all_params.append("_return_http_data_only")
        all_params.append("_preload_content")
        all_params.append("_request_timeout")

        params = locals()
        for key, val in six.iteritems(params["kwargs"]):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method update_installment_payment" % key
                )
            params[key] = val
        del params["kwargs"]
        # verify the required parameter 'recurring_id' is set
        if "recurring_id" not in params or params["recurring_id"] is None:
            raise ValueError(
                "Missing the required parameter `recurring_id` when calling `update_installment_payment`"
            )  # noqa: E501
        # verify the required parameter 'recurring_patch_request' is set
        if (
            "recurring_patch_request" not in params
            or params["recurring_patch_request"] is None
        ):
            raise ValueError(
                "Missing the required parameter `recurring_patch_request` when calling `update_installment_payment`"
            )  # noqa: E501

        collection_formats = {}

        path_params = {}
        if "recurring_id" in params:
            path_params["recurringId"] = params["recurring_id"]  # noqa: E501

        query_params = []

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        if "recurring_patch_request" in params:
            body_params = params["recurring_patch_request"]
        # HTTP header `Accept`
        header_params["Accept"] = self.api_client.select_header_accept(
            ["application/json"]
        )  # noqa: E501
        # HTTP header `Content-Type`
        header_params[
            "Content-Type"
        ] = self.api_client.select_header_content_type(  # noqa: E501
            ["application/json"]
        )  # noqa: E501

        return self.api_client.call_api(
            "/api/installments/{recurringId}",
            "PATCH",
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type="RecurringResponse",  # noqa: E501
            _return_http_data_only=params.get("_return_http_data_only"),
            _preload_content=params.get("_preload_content", True),
            _request_timeout=params.get("_request_timeout"),
            collection_formats=collection_formats,
        )
