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

import datetime as dt
import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from ..types.feature_collection import FeatureCollection
from ..types.time_series_feature_collection_model import TimeSeriesFeatureCollectionModel
from .raw_client import AsyncRawPortfoliosClient, RawPortfoliosClient


class PortfoliosClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawPortfoliosClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> RawPortfoliosClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        RawPortfoliosClient
        """
        return self._raw_client

    def features(
        self,
        portfolio_id: str,
        *,
        x: typing.Optional[int] = None,
        y: typing.Optional[int] = None,
        z: typing.Optional[int] = None,
        country: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> FeatureCollection:
        """
        Return a GeoJSON FeatureCollection of features for a portfolio.

        Parameters
        ----------
        portfolio_id : str

        x : typing.Optional[int]

        y : typing.Optional[int]

        z : typing.Optional[int]

        country : typing.Optional[str]

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

        Returns
        -------
        FeatureCollection
            Successful Response

        Examples
        --------
        from silurian import Earth

        client = Earth(
            api_key="YOUR_API_KEY",
        )
        client.portfolios.features(
            portfolio_id="portfolio_id",
            x=1,
            y=1,
            z=1,
            country="country",
        )
        """
        _response = self._raw_client.features(
            portfolio_id, x=x, y=y, z=z, country=country, request_options=request_options
        )
        return _response.data

    def forecasts(
        self,
        portfolio_id: str,
        *,
        init_time: dt.datetime,
        id: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        variables: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TimeSeriesFeatureCollectionModel:
        """
        Return a GeoJSON FeatureCollection of forecasts for a portfolio.

        Parameters
        ----------
        portfolio_id : str

        init_time : dt.datetime

        id : typing.Optional[typing.Union[str, typing.Sequence[str]]]

        variables : typing.Optional[typing.Union[str, typing.Sequence[str]]]

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

        Returns
        -------
        TimeSeriesFeatureCollectionModel
            Successful Response

        Examples
        --------
        import datetime

        from silurian import Earth

        client = Earth(
            api_key="YOUR_API_KEY",
        )
        client.portfolios.forecasts(
            portfolio_id="portfolio_id",
            init_time=datetime.datetime.fromisoformat(
                "2024-01-15 09:30:00+00:00",
            ),
        )
        """
        _response = self._raw_client.forecasts(
            portfolio_id, init_time=init_time, id=id, variables=variables, request_options=request_options
        )
        return _response.data

    def observations(
        self,
        portfolio_id: str,
        *,
        valid_time_start: dt.datetime,
        valid_time_end: dt.datetime,
        id: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        variables: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TimeSeriesFeatureCollectionModel:
        """
        Return a GeoJSON FeatureCollection of observations for a portfolio.

        Parameters
        ----------
        portfolio_id : str

        valid_time_start : dt.datetime

        valid_time_end : dt.datetime

        id : typing.Optional[typing.Union[str, typing.Sequence[str]]]

        variables : typing.Optional[typing.Union[str, typing.Sequence[str]]]

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

        Returns
        -------
        TimeSeriesFeatureCollectionModel
            Successful Response

        Examples
        --------
        import datetime

        from silurian import Earth

        client = Earth(
            api_key="YOUR_API_KEY",
        )
        client.portfolios.observations(
            portfolio_id="portfolio_id",
            valid_time_start=datetime.datetime.fromisoformat(
                "2024-01-15 09:30:00+00:00",
            ),
            valid_time_end=datetime.datetime.fromisoformat(
                "2024-01-15 09:30:00+00:00",
            ),
        )
        """
        _response = self._raw_client.observations(
            portfolio_id,
            valid_time_start=valid_time_start,
            valid_time_end=valid_time_end,
            id=id,
            variables=variables,
            request_options=request_options,
        )
        return _response.data

    def init_time(
        self, portfolio_id: str, *, time: dt.datetime, request_options: typing.Optional[RequestOptions] = None
    ) -> dt.datetime:
        """
        Return the latest initialization time for a portfolio.

        Parameters
        ----------
        portfolio_id : str

        time : dt.datetime

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

        Returns
        -------
        dt.datetime
            Successful Response

        Examples
        --------
        import datetime

        from silurian import Earth

        client = Earth(
            api_key="YOUR_API_KEY",
        )
        client.portfolios.init_time(
            portfolio_id="portfolio_id",
            time=datetime.datetime.fromisoformat(
                "2024-01-15 09:30:00+00:00",
            ),
        )
        """
        _response = self._raw_client.init_time(portfolio_id, time=time, request_options=request_options)
        return _response.data


class AsyncPortfoliosClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawPortfoliosClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> AsyncRawPortfoliosClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        AsyncRawPortfoliosClient
        """
        return self._raw_client

    async def features(
        self,
        portfolio_id: str,
        *,
        x: typing.Optional[int] = None,
        y: typing.Optional[int] = None,
        z: typing.Optional[int] = None,
        country: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> FeatureCollection:
        """
        Return a GeoJSON FeatureCollection of features for a portfolio.

        Parameters
        ----------
        portfolio_id : str

        x : typing.Optional[int]

        y : typing.Optional[int]

        z : typing.Optional[int]

        country : typing.Optional[str]

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

        Returns
        -------
        FeatureCollection
            Successful Response

        Examples
        --------
        import asyncio

        from silurian import AsyncEarth

        client = AsyncEarth(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.portfolios.features(
                portfolio_id="portfolio_id",
                x=1,
                y=1,
                z=1,
                country="country",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.features(
            portfolio_id, x=x, y=y, z=z, country=country, request_options=request_options
        )
        return _response.data

    async def forecasts(
        self,
        portfolio_id: str,
        *,
        init_time: dt.datetime,
        id: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        variables: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TimeSeriesFeatureCollectionModel:
        """
        Return a GeoJSON FeatureCollection of forecasts for a portfolio.

        Parameters
        ----------
        portfolio_id : str

        init_time : dt.datetime

        id : typing.Optional[typing.Union[str, typing.Sequence[str]]]

        variables : typing.Optional[typing.Union[str, typing.Sequence[str]]]

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

        Returns
        -------
        TimeSeriesFeatureCollectionModel
            Successful Response

        Examples
        --------
        import asyncio
        import datetime

        from silurian import AsyncEarth

        client = AsyncEarth(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.portfolios.forecasts(
                portfolio_id="portfolio_id",
                init_time=datetime.datetime.fromisoformat(
                    "2024-01-15 09:30:00+00:00",
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.forecasts(
            portfolio_id, init_time=init_time, id=id, variables=variables, request_options=request_options
        )
        return _response.data

    async def observations(
        self,
        portfolio_id: str,
        *,
        valid_time_start: dt.datetime,
        valid_time_end: dt.datetime,
        id: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        variables: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TimeSeriesFeatureCollectionModel:
        """
        Return a GeoJSON FeatureCollection of observations for a portfolio.

        Parameters
        ----------
        portfolio_id : str

        valid_time_start : dt.datetime

        valid_time_end : dt.datetime

        id : typing.Optional[typing.Union[str, typing.Sequence[str]]]

        variables : typing.Optional[typing.Union[str, typing.Sequence[str]]]

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

        Returns
        -------
        TimeSeriesFeatureCollectionModel
            Successful Response

        Examples
        --------
        import asyncio
        import datetime

        from silurian import AsyncEarth

        client = AsyncEarth(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.portfolios.observations(
                portfolio_id="portfolio_id",
                valid_time_start=datetime.datetime.fromisoformat(
                    "2024-01-15 09:30:00+00:00",
                ),
                valid_time_end=datetime.datetime.fromisoformat(
                    "2024-01-15 09:30:00+00:00",
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.observations(
            portfolio_id,
            valid_time_start=valid_time_start,
            valid_time_end=valid_time_end,
            id=id,
            variables=variables,
            request_options=request_options,
        )
        return _response.data

    async def init_time(
        self, portfolio_id: str, *, time: dt.datetime, request_options: typing.Optional[RequestOptions] = None
    ) -> dt.datetime:
        """
        Return the latest initialization time for a portfolio.

        Parameters
        ----------
        portfolio_id : str

        time : dt.datetime

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

        Returns
        -------
        dt.datetime
            Successful Response

        Examples
        --------
        import asyncio
        import datetime

        from silurian import AsyncEarth

        client = AsyncEarth(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.portfolios.init_time(
                portfolio_id="portfolio_id",
                time=datetime.datetime.fromisoformat(
                    "2024-01-15 09:30:00+00:00",
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.init_time(portfolio_id, time=time, request_options=request_options)
        return _response.data
