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

import requests
import sdkgen

from backend_token import BackendToken
from backend_token_collection import BackendTokenCollection
from common_message_exception import CommonMessageException

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


    def get(self, token_id: str) -> BackendToken:
        try:
            pathParams = {}
            pathParams["token_id"] = token_id

            queryParams = {}

            queryStructNames = [];

            url = self.parser.url("/backend/token/$token_id<[0-9]+>", pathParams)

            headers = {}

            response = self.http_client.get(url, headers=headers, params=this.parser.query(queryParams, queryStructNames))

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

            if response.status_code == 401:
                raise CommonMessageException(CommonMessage.from_json(response.content))
            if response.status_code == 404:
                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 get_all(self, start_index: int, count: int, search: str, _from: str, to: str, app_id: int, user_id: int, status: int, scope: str, ip: str) -> BackendTokenCollection:
        try:
            pathParams = {}

            queryParams = {}
            queryParams["startIndex"] = start_index
            queryParams["count"] = count
            queryParams["search"] = search
            queryParams["from"] = _from
            queryParams["to"] = to
            queryParams["appId"] = app_id
            queryParams["userId"] = user_id
            queryParams["status"] = status
            queryParams["scope"] = scope
            queryParams["ip"] = ip

            queryStructNames = [];

            url = self.parser.url("/backend/token", pathParams)

            headers = {}

            response = self.http_client.get(url, headers=headers, params=this.parser.query(queryParams, queryStructNames))

            if response.status_code >= 200 and response.status_code < 300:
                return BackendTokenCollection.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


