"""
ConsumerPaymentTag automatically generated by SDKgen please do not edit this file manually
https://sdkgen.app
"""

import requests
import sdkgen

from common_message_exception import CommonMessageException
from consumer_payment_checkout_request import ConsumerPaymentCheckoutRequest
from consumer_payment_checkout_response import ConsumerPaymentCheckoutResponse
from consumer_payment_portal_request import ConsumerPaymentPortalRequest
from consumer_payment_portal_response import ConsumerPaymentPortalResponse

class ConsumerPaymentTag(sdkgen.TagAbstract):
    def __init__(self, http_client: requests.Session, parser: sdkgen.Parser):
        super().__init__(http_client, parser)
    pass


    def checkout(self, provider: str, payload: ConsumerPaymentCheckoutRequest) -> ConsumerPaymentCheckoutResponse:
        try:
            pathParams = {}
            pathParams["provider"] = provider

            queryParams = {}

            queryStructNames = [];

            url = self.parser.url("/consumer/payment/:provider/checkout", pathParams)

            headers = {}
            headers["Content-Type"] = "application/json"

            response = self.http_client.post(url, headers=headers, params=this.parser.query(queryParams, queryStructNames), data=payload.to_json())

            if response.status_code >= 200 and response.status_code < 300:
                return ConsumerPaymentCheckoutResponse.from_json(response.content)

            if response.status_code == 401:
                raise CommonMessageException(CommonMessage.from_json(response.content))
            if response.status_code == 500:
                raise CommonMessageException(CommonMessage.from_json(response.content))

            raise sdkgen.UnknownStatusCodeException("The server returned an unknown status code")
        except Exception as e:
            raise sdkgen.ClientException("An unknown error occurred: " + str(e))
    pass

    def portal(self, provider: str, payload: ConsumerPaymentPortalRequest) -> ConsumerPaymentPortalResponse:
        try:
            pathParams = {}
            pathParams["provider"] = provider

            queryParams = {}

            queryStructNames = [];

            url = self.parser.url("/consumer/payment/:provider/portal", pathParams)

            headers = {}
            headers["Content-Type"] = "application/json"

            response = self.http_client.post(url, headers=headers, params=this.parser.query(queryParams, queryStructNames), data=payload.to_json())

            if response.status_code >= 200 and response.status_code < 300:
                return ConsumerPaymentPortalResponse.from_json(response.content)

            if response.status_code == 401:
                raise CommonMessageException(CommonMessage.from_json(response.content))
            if response.status_code == 500:
                raise CommonMessageException(CommonMessage.from_json(response.content))

            raise sdkgen.UnknownStatusCodeException("The server returned an unknown status code")
        except Exception as e:
            raise sdkgen.ClientException("An unknown error occurred: " + str(e))
    pass


