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

import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from ..types.list_universes_response import ListUniversesResponse
from ..types.release_universe_response import ReleaseUniverseResponse
from ..types.task_details import TaskDetails
from ..types.universe_instance import UniverseInstance
from ..types.verify_task_response import VerifyTaskResponse
from .raw_client import AsyncRawUniverseClient, RawUniverseClient


class UniverseClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawUniverseClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawUniverseClient
        """
        return self._raw_client

    def list_universes(self, *, request_options: typing.Optional[RequestOptions] = None) -> ListUniversesResponse:
        """
        List all available universes.

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

        Returns
        -------
        ListUniversesResponse
            Successful Response

        Examples
        --------
        from klavis import Klavis

        client = Klavis(
            api_key="YOUR_API_KEY",
        )
        client.universe.list_universes()
        """
        _response = self._raw_client.list_universes(request_options=request_options)
        return _response.data

    def get_universe_data(
        self, universe_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.Optional[typing.Any]:
        """
        Get universe initial data for all services.

        Parameters
        ----------
        universe_id : str

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

        Returns
        -------
        typing.Optional[typing.Any]
            Successful Response

        Examples
        --------
        from klavis import Klavis

        client = Klavis(
            api_key="YOUR_API_KEY",
        )
        client.universe.get_universe_data(
            universe_id="universe_id",
        )
        """
        _response = self._raw_client.get_universe_data(universe_id, request_options=request_options)
        return _response.data

    def acquire_universe(
        self, universe_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> UniverseInstance:
        """
        Acquire the next idle universe instance.

        Parameters
        ----------
        universe_id : str

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

        Returns
        -------
        UniverseInstance
            Successful Response

        Examples
        --------
        from klavis import Klavis

        client = Klavis(
            api_key="YOUR_API_KEY",
        )
        client.universe.acquire_universe(
            universe_id="universe_id",
        )
        """
        _response = self._raw_client.acquire_universe(universe_id, request_options=request_options)
        return _response.data

    def release_universe(
        self, universe_instance_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ReleaseUniverseResponse:
        """
        Release and Reinitialize the universe to its initial state.

        This immediately returns and handles reset/initialization in the background.
        Only gcalendar and notion setup methods use sandbox (which call reset internally).
        Others need explicit reset before re-initialization.

        Parameters
        ----------
        universe_instance_id : str

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

        Returns
        -------
        ReleaseUniverseResponse
            Successful Response

        Examples
        --------
        from klavis import Klavis

        client = Klavis(
            api_key="YOUR_API_KEY",
        )
        client.universe.release_universe(
            universe_instance_id="universe_instance_id",
        )
        """
        _response = self._raw_client.release_universe(universe_instance_id, request_options=request_options)
        return _response.data

    def get_task(
        self, universe_id: str, task_num: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> TaskDetails:
        """
        Get task details within a universe instance.

        Parameters
        ----------
        universe_id : str

        task_num : str

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

        Returns
        -------
        TaskDetails
            Successful Response

        Examples
        --------
        from klavis import Klavis

        client = Klavis(
            api_key="YOUR_API_KEY",
        )
        client.universe.get_task(
            universe_id="universe_id",
            task_num="task_num",
        )
        """
        _response = self._raw_client.get_task(universe_id, task_num, request_options=request_options)
        return _response.data

    def verify_task(
        self, universe_instance_id: str, task_num: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> VerifyTaskResponse:
        """
        Verify if the task has been performed correctly by running the task's verify function.

        Parameters
        ----------
        universe_instance_id : str

        task_num : str

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

        Returns
        -------
        VerifyTaskResponse
            Successful Response

        Examples
        --------
        from klavis import Klavis

        client = Klavis(
            api_key="YOUR_API_KEY",
        )
        client.universe.verify_task(
            universe_instance_id="universe_instance_id",
            task_num="task_num",
        )
        """
        _response = self._raw_client.verify_task(universe_instance_id, task_num, request_options=request_options)
        return _response.data


class AsyncUniverseClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawUniverseClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawUniverseClient
        """
        return self._raw_client

    async def list_universes(self, *, request_options: typing.Optional[RequestOptions] = None) -> ListUniversesResponse:
        """
        List all available universes.

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

        Returns
        -------
        ListUniversesResponse
            Successful Response

        Examples
        --------
        import asyncio

        from klavis import AsyncKlavis

        client = AsyncKlavis(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.universe.list_universes()


        asyncio.run(main())
        """
        _response = await self._raw_client.list_universes(request_options=request_options)
        return _response.data

    async def get_universe_data(
        self, universe_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.Optional[typing.Any]:
        """
        Get universe initial data for all services.

        Parameters
        ----------
        universe_id : str

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

        Returns
        -------
        typing.Optional[typing.Any]
            Successful Response

        Examples
        --------
        import asyncio

        from klavis import AsyncKlavis

        client = AsyncKlavis(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.universe.get_universe_data(
                universe_id="universe_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_universe_data(universe_id, request_options=request_options)
        return _response.data

    async def acquire_universe(
        self, universe_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> UniverseInstance:
        """
        Acquire the next idle universe instance.

        Parameters
        ----------
        universe_id : str

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

        Returns
        -------
        UniverseInstance
            Successful Response

        Examples
        --------
        import asyncio

        from klavis import AsyncKlavis

        client = AsyncKlavis(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.universe.acquire_universe(
                universe_id="universe_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.acquire_universe(universe_id, request_options=request_options)
        return _response.data

    async def release_universe(
        self, universe_instance_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ReleaseUniverseResponse:
        """
        Release and Reinitialize the universe to its initial state.

        This immediately returns and handles reset/initialization in the background.
        Only gcalendar and notion setup methods use sandbox (which call reset internally).
        Others need explicit reset before re-initialization.

        Parameters
        ----------
        universe_instance_id : str

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

        Returns
        -------
        ReleaseUniverseResponse
            Successful Response

        Examples
        --------
        import asyncio

        from klavis import AsyncKlavis

        client = AsyncKlavis(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.universe.release_universe(
                universe_instance_id="universe_instance_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.release_universe(universe_instance_id, request_options=request_options)
        return _response.data

    async def get_task(
        self, universe_id: str, task_num: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> TaskDetails:
        """
        Get task details within a universe instance.

        Parameters
        ----------
        universe_id : str

        task_num : str

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

        Returns
        -------
        TaskDetails
            Successful Response

        Examples
        --------
        import asyncio

        from klavis import AsyncKlavis

        client = AsyncKlavis(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.universe.get_task(
                universe_id="universe_id",
                task_num="task_num",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_task(universe_id, task_num, request_options=request_options)
        return _response.data

    async def verify_task(
        self, universe_instance_id: str, task_num: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> VerifyTaskResponse:
        """
        Verify if the task has been performed correctly by running the task's verify function.

        Parameters
        ----------
        universe_instance_id : str

        task_num : str

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

        Returns
        -------
        VerifyTaskResponse
            Successful Response

        Examples
        --------
        import asyncio

        from klavis import AsyncKlavis

        client = AsyncKlavis(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.universe.verify_task(
                universe_instance_id="universe_instance_id",
                task_num="task_num",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.verify_task(universe_instance_id, task_num, request_options=request_options)
        return _response.data
