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

import requests
import sdkgen
from requests import RequestException
from typing import List

from .common_message_exception import CommonMessageException
from .consumer_identity_collection import ConsumerIdentityCollection
from .passthru import Passthru

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


    def redirect(self, identity: str) -> Passthru:
        try:
            path_params = {}
            path_params["identity"] = identity

            query_params = {}

            query_struct_names = []

            url = self.parser.url("/consumer/identity/:identity/redirect", path_params)

            headers = {}

            response = self.http_client.get(url, headers=headers, params=self.parser.query(query_params, query_struct_names))

            if response.status_code >= 200 and response.status_code < 300:
                return Passthru.model_validate_json(json_data=response.content)

            if response.status_code == 400:
                raise CommonMessageException(response.content)
            if response.status_code == 500:
                raise CommonMessageException(response.content)

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

    def exchange(self, identity: str) -> Passthru:
        try:
            path_params = {}
            path_params["identity"] = identity

            query_params = {}

            query_struct_names = []

            url = self.parser.url("/consumer/identity/:identity/exchange", path_params)

            headers = {}

            response = self.http_client.get(url, headers=headers, params=self.parser.query(query_params, query_struct_names))

            if response.status_code >= 200 and response.status_code < 300:
                return Passthru.model_validate_json(json_data=response.content)

            if response.status_code == 400:
                raise CommonMessageException(response.content)
            if response.status_code == 500:
                raise CommonMessageException(response.content)

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

    def get_all(self, app_id: int, app_key: str) -> ConsumerIdentityCollection:
        try:
            path_params = {}

            query_params = {}
            query_params["appId"] = app_id
            query_params["appKey"] = app_key

            query_struct_names = []

            url = self.parser.url("/consumer/identity", path_params)

            headers = {}

            response = self.http_client.get(url, headers=headers, params=self.parser.query(query_params, query_struct_names))

            if response.status_code >= 200 and response.status_code < 300:
                return ConsumerIdentityCollection.model_validate_json(json_data=response.content)

            if response.status_code == 400:
                raise CommonMessageException(response.content)
            if response.status_code == 500:
                raise CommonMessageException(response.content)

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


