# This file was auto-generated by Fern from our API Definition.

from ...core.client_wrapper import SyncClientWrapper
import typing
from ...types.units import Units
from ...core.request_options import RequestOptions
from ...core.http_response import HttpResponse
from ...types.daily_weather_response import DailyWeatherResponse
from ...core.pydantic_utilities import parse_obj_as
from ...errors.unprocessable_entity_error import UnprocessableEntityError
from ...types.http_validation_error import HttpValidationError
from json.decoder import JSONDecodeError
from ...core.api_error import ApiError
from ...types.timezone import Timezone
from ...types.hourly_weather_response import HourlyWeatherResponse
from ...core.client_wrapper import AsyncClientWrapper
from ...core.http_response import AsyncHttpResponse


class RawForecastClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._client_wrapper = client_wrapper

    def daily(
        self,
        *,
        latitude: float,
        longitude: float,
        timezone: typing.Optional[typing.Literal["local"]] = None,
        units: typing.Optional[Units] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[DailyWeatherResponse]:
        """
        Get daily weather forecast for a specific location
        Only allowing local timezone aggregations for now since
        it is unclear how exactly users will understand "UTC".

        Parameters
        ----------
        latitude : float

        longitude : float

        timezone : typing.Optional[typing.Literal["local"]]

        units : typing.Optional[Units]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[DailyWeatherResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "forecast/daily",
            method="GET",
            params={
                "latitude": latitude,
                "longitude": longitude,
                "timezone": timezone,
                "units": units,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    DailyWeatherResponse,
                    parse_obj_as(
                        type_=DailyWeatherResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def hourly(
        self,
        *,
        latitude: float,
        longitude: float,
        timezone: typing.Optional[Timezone] = None,
        units: typing.Optional[Units] = None,
        include_past: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[HourlyWeatherResponse]:
        """
        Get hourly weather forecast for a specific location

        Parameters
        ----------
        latitude : float

        longitude : float

        timezone : typing.Optional[Timezone]

        units : typing.Optional[Units]

        include_past : typing.Optional[bool]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[HourlyWeatherResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "forecast/hourly",
            method="GET",
            params={
                "latitude": latitude,
                "longitude": longitude,
                "timezone": timezone,
                "units": units,
                "include_past": include_past,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    HourlyWeatherResponse,
                    parse_obj_as(
                        type_=HourlyWeatherResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)


class AsyncRawForecastClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def daily(
        self,
        *,
        latitude: float,
        longitude: float,
        timezone: typing.Optional[typing.Literal["local"]] = None,
        units: typing.Optional[Units] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[DailyWeatherResponse]:
        """
        Get daily weather forecast for a specific location
        Only allowing local timezone aggregations for now since
        it is unclear how exactly users will understand "UTC".

        Parameters
        ----------
        latitude : float

        longitude : float

        timezone : typing.Optional[typing.Literal["local"]]

        units : typing.Optional[Units]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[DailyWeatherResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "forecast/daily",
            method="GET",
            params={
                "latitude": latitude,
                "longitude": longitude,
                "timezone": timezone,
                "units": units,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    DailyWeatherResponse,
                    parse_obj_as(
                        type_=DailyWeatherResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def hourly(
        self,
        *,
        latitude: float,
        longitude: float,
        timezone: typing.Optional[Timezone] = None,
        units: typing.Optional[Units] = None,
        include_past: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[HourlyWeatherResponse]:
        """
        Get hourly weather forecast for a specific location

        Parameters
        ----------
        latitude : float

        longitude : float

        timezone : typing.Optional[Timezone]

        units : typing.Optional[Units]

        include_past : typing.Optional[bool]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[HourlyWeatherResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "forecast/hourly",
            method="GET",
            params={
                "latitude": latitude,
                "longitude": longitude,
                "timezone": timezone,
                "units": units,
                "include_past": include_past,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    HourlyWeatherResponse,
                    parse_obj_as(
                        type_=HourlyWeatherResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)
