"""
CityTag 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 .city import City
from .city_collection import CityCollection
from .response_exception import ResponseException

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


    def get(self, city_id: str) -> City:
        """
        Returns a specific city
        """
        try:
            path_params = {}
            path_params["city_id"] = city_id

            query_params = {}

            query_struct_names = []

            url = self.parser.url("/city/:city_id", 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 City.model_validate_json(json_data=response.content)

            if response.status_code == 400:
                raise ResponseException(response.content)
            if response.status_code == 404:
                raise ResponseException(response.content)
            if response.status_code == 500:
                raise ResponseException(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, start_index: int, state: str, district: str, name: str, zip_code: str) -> CityCollection:
        """
        Returns all available cities
        """
        try:
            path_params = {}

            query_params = {}
            query_params["startIndex"] = start_index
            query_params["state"] = state
            query_params["district"] = district
            query_params["name"] = name
            query_params["zipCode"] = zip_code

            query_struct_names = []

            url = self.parser.url("/city", 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 CityCollection.model_validate_json(json_data=response.content)

            if response.status_code == 400:
                raise ResponseException(response.content)
            if response.status_code == 404:
                raise ResponseException(response.content)
            if response.status_code == 500:
                raise ResponseException(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))


