# 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.app import App
from ..types.app_variant_response import AppVariantResponse
from ..types.create_app_output import CreateAppOutput
from ..types.environment_output import EnvironmentOutput
from ..types.environment_output_extended import EnvironmentOutputExtended
from ..types.update_app_output import UpdateAppOutput
from .raw_client import AsyncRawAppsClient, RawAppsClient

# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class AppsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawAppsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawAppsClient
        """
        return self._raw_client

    def list_app_variants(
        self, app_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[AppVariantResponse]:
        """
        Retrieve a list of app variants for a given app ID.

        Args:
            app_id (str): The ID of the app to retrieve variants for.

        Returns:
            List[AppVariantResponse]: A list of app variants for the given app ID.

        Parameters
        ----------
        app_id : str

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

        Returns
        -------
        typing.List[AppVariantResponse]
            Successful Response

        Examples
        --------
        from agenta import AgentaApi

        client = AgentaApi(
            api_key="YOUR_API_KEY",
        )
        client.apps.list_app_variants(
            app_id="app_id",
        )
        """
        _response = self._raw_client.list_app_variants(
            app_id, request_options=request_options
        )
        return _response.data

    def get_variant_by_env(
        self,
        *,
        app_id: str,
        environment: str,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AppVariantResponse:
        """
        Retrieve the app variant based on the provided app_id and environment.

        Args:
            app_id (str): The ID of the app to retrieve the variant for.
            environment (str): The environment of the app variant to retrieve.

        Raises:
            HTTPException: If the app variant is not found (status_code=500), or if a ValueError is raised (status_code=400), or if any other exception is raised (status_code=500).

        Returns:
            AppVariantResponse: The retrieved app variant.

        Parameters
        ----------
        app_id : str

        environment : str

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

        Returns
        -------
        AppVariantResponse
            Successful Response

        Examples
        --------
        from agenta import AgentaApi

        client = AgentaApi(
            api_key="YOUR_API_KEY",
        )
        client.apps.get_variant_by_env(
            app_id="app_id",
            environment="environment",
        )
        """
        _response = self._raw_client.get_variant_by_env(
            app_id=app_id, environment=environment, request_options=request_options
        )
        return _response.data

    def list_apps(
        self,
        *,
        app_name: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[App]:
        """
        Retrieve a list of apps filtered by app_name.

        Args:
            app_name (Optional[str]): The name of the app to filter by.

        Returns:
            List[App]: A list of apps filtered by app_name.

        Raises:
            HTTPException: If there was an error retrieving the list of apps.

        Parameters
        ----------
        app_name : typing.Optional[str]

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

        Returns
        -------
        typing.List[App]
            Successful Response

        Examples
        --------
        from agenta import AgentaApi

        client = AgentaApi(
            api_key="YOUR_API_KEY",
        )
        client.apps.list_apps()
        """
        _response = self._raw_client.list_apps(
            app_name=app_name, request_options=request_options
        )
        return _response.data

    def create_app(
        self,
        *,
        app_name: str,
        template_key: typing.Optional[str] = OMIT,
        project_id: typing.Optional[str] = OMIT,
        workspace_id: typing.Optional[str] = OMIT,
        organization_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateAppOutput:
        """
        Create a new app for a user or organization.

        Args:
            payload (CreateApp): The payload containing the app name and organization ID (optional).

        Returns:
            CreateAppOutput: The output containing the newly created app's ID and name.

        Raises:
            HTTPException: If there is an error creating the app or the user does not have permission to access the app.

        Parameters
        ----------
        app_name : str

        template_key : typing.Optional[str]

        project_id : typing.Optional[str]

        workspace_id : typing.Optional[str]

        organization_id : typing.Optional[str]

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

        Returns
        -------
        CreateAppOutput
            Successful Response

        Examples
        --------
        from agenta import AgentaApi

        client = AgentaApi(
            api_key="YOUR_API_KEY",
        )
        client.apps.create_app(
            app_name="app_name",
        )
        """
        _response = self._raw_client.create_app(
            app_name=app_name,
            template_key=template_key,
            project_id=project_id,
            workspace_id=workspace_id,
            organization_id=organization_id,
            request_options=request_options,
        )
        return _response.data

    def remove_app(
        self, app_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.Optional[typing.Any]:
        """
        Remove app, all its variant.

        Arguments:
            app -- App to remove

        Parameters
        ----------
        app_id : str

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

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

        Examples
        --------
        from agenta import AgentaApi

        client = AgentaApi(
            api_key="YOUR_API_KEY",
        )
        client.apps.remove_app(
            app_id="app_id",
        )
        """
        _response = self._raw_client.remove_app(app_id, request_options=request_options)
        return _response.data

    def update_app(
        self,
        app_id: str,
        *,
        app_name: str,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpdateAppOutput:
        """
        Update an app for a user or organization.

        Args:
            app_id (str): The ID of the app.
            payload (UpdateApp): The payload containing the app name.

        Returns:
            UpdateAppOutput: The output containing the newly created app's ID and name.

        Raises:
            HTTPException: If there is an error creating the app or the user does not have permission to access the app.

        Parameters
        ----------
        app_id : str

        app_name : str

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

        Returns
        -------
        UpdateAppOutput
            Successful Response

        Examples
        --------
        from agenta import AgentaApi

        client = AgentaApi(
            api_key="YOUR_API_KEY",
        )
        client.apps.update_app(
            app_id="app_id",
            app_name="app_name",
        )
        """
        _response = self._raw_client.update_app(
            app_id, app_name=app_name, request_options=request_options
        )
        return _response.data

    def add_variant_from_url(
        self,
        app_id: str,
        *,
        variant_name: str,
        url: str,
        commit_message: typing.Optional[str] = OMIT,
        base_name: typing.Optional[str] = OMIT,
        config_name: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Optional[typing.Any]:
        """
        Parameters
        ----------
        app_id : str

        variant_name : str

        url : str

        commit_message : typing.Optional[str]

        base_name : typing.Optional[str]

        config_name : typing.Optional[str]

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

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

        Examples
        --------
        from agenta import AgentaApi

        client = AgentaApi(
            api_key="YOUR_API_KEY",
        )
        client.apps.add_variant_from_url(
            app_id="app_id",
            variant_name="variant_name",
            url="url",
        )
        """
        _response = self._raw_client.add_variant_from_url(
            app_id,
            variant_name=variant_name,
            url=url,
            commit_message=commit_message,
            base_name=base_name,
            config_name=config_name,
            request_options=request_options,
        )
        return _response.data

    def add_variant_from_key(
        self,
        app_id: str,
        *,
        variant_name: str,
        key: str,
        commit_message: typing.Optional[str] = OMIT,
        base_name: typing.Optional[str] = OMIT,
        config_name: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Optional[typing.Any]:
        """
        Parameters
        ----------
        app_id : str

        variant_name : str

        key : str

        commit_message : typing.Optional[str]

        base_name : typing.Optional[str]

        config_name : typing.Optional[str]

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

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

        Examples
        --------
        from agenta import AgentaApi

        client = AgentaApi(
            api_key="YOUR_API_KEY",
        )
        client.apps.add_variant_from_key(
            app_id="app_id",
            variant_name="variant_name",
            key="key",
        )
        """
        _response = self._raw_client.add_variant_from_key(
            app_id,
            variant_name=variant_name,
            key=key,
            commit_message=commit_message,
            base_name=base_name,
            config_name=config_name,
            request_options=request_options,
        )
        return _response.data

    def list_environments(
        self, app_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[EnvironmentOutput]:
        """
        Retrieve a list of environments for a given app ID.

        Args:
            app_id (str): The ID of the app to retrieve environments for.

        Returns:
            List[EnvironmentOutput]: A list of environment objects.

        Parameters
        ----------
        app_id : str

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

        Returns
        -------
        typing.List[EnvironmentOutput]
            Successful Response

        Examples
        --------
        from agenta import AgentaApi

        client = AgentaApi(
            api_key="YOUR_API_KEY",
        )
        client.apps.list_environments(
            app_id="app_id",
        )
        """
        _response = self._raw_client.list_environments(
            app_id, request_options=request_options
        )
        return _response.data

    def environment_revisions(
        self,
        app_id: str,
        environment_name: typing.Optional[typing.Any],
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EnvironmentOutputExtended:
        """
        Parameters
        ----------
        app_id : str

        environment_name : typing.Optional[typing.Any]

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

        Returns
        -------
        EnvironmentOutputExtended
            Successful Response

        Examples
        --------
        from agenta import AgentaApi

        client = AgentaApi(
            api_key="YOUR_API_KEY",
        )
        client.apps.environment_revisions(
            app_id="app_id",
            environment_name={"key": "value"},
        )
        """
        _response = self._raw_client.environment_revisions(
            app_id, environment_name, request_options=request_options
        )
        return _response.data


class AsyncAppsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawAppsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawAppsClient
        """
        return self._raw_client

    async def list_app_variants(
        self, app_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[AppVariantResponse]:
        """
        Retrieve a list of app variants for a given app ID.

        Args:
            app_id (str): The ID of the app to retrieve variants for.

        Returns:
            List[AppVariantResponse]: A list of app variants for the given app ID.

        Parameters
        ----------
        app_id : str

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

        Returns
        -------
        typing.List[AppVariantResponse]
            Successful Response

        Examples
        --------
        import asyncio

        from agenta import AsyncAgentaApi

        client = AsyncAgentaApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.apps.list_app_variants(
                app_id="app_id",
            )


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

    async def get_variant_by_env(
        self,
        *,
        app_id: str,
        environment: str,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AppVariantResponse:
        """
        Retrieve the app variant based on the provided app_id and environment.

        Args:
            app_id (str): The ID of the app to retrieve the variant for.
            environment (str): The environment of the app variant to retrieve.

        Raises:
            HTTPException: If the app variant is not found (status_code=500), or if a ValueError is raised (status_code=400), or if any other exception is raised (status_code=500).

        Returns:
            AppVariantResponse: The retrieved app variant.

        Parameters
        ----------
        app_id : str

        environment : str

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

        Returns
        -------
        AppVariantResponse
            Successful Response

        Examples
        --------
        import asyncio

        from agenta import AsyncAgentaApi

        client = AsyncAgentaApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.apps.get_variant_by_env(
                app_id="app_id",
                environment="environment",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_variant_by_env(
            app_id=app_id, environment=environment, request_options=request_options
        )
        return _response.data

    async def list_apps(
        self,
        *,
        app_name: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[App]:
        """
        Retrieve a list of apps filtered by app_name.

        Args:
            app_name (Optional[str]): The name of the app to filter by.

        Returns:
            List[App]: A list of apps filtered by app_name.

        Raises:
            HTTPException: If there was an error retrieving the list of apps.

        Parameters
        ----------
        app_name : typing.Optional[str]

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

        Returns
        -------
        typing.List[App]
            Successful Response

        Examples
        --------
        import asyncio

        from agenta import AsyncAgentaApi

        client = AsyncAgentaApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.apps.list_apps()


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

    async def create_app(
        self,
        *,
        app_name: str,
        template_key: typing.Optional[str] = OMIT,
        project_id: typing.Optional[str] = OMIT,
        workspace_id: typing.Optional[str] = OMIT,
        organization_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateAppOutput:
        """
        Create a new app for a user or organization.

        Args:
            payload (CreateApp): The payload containing the app name and organization ID (optional).

        Returns:
            CreateAppOutput: The output containing the newly created app's ID and name.

        Raises:
            HTTPException: If there is an error creating the app or the user does not have permission to access the app.

        Parameters
        ----------
        app_name : str

        template_key : typing.Optional[str]

        project_id : typing.Optional[str]

        workspace_id : typing.Optional[str]

        organization_id : typing.Optional[str]

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

        Returns
        -------
        CreateAppOutput
            Successful Response

        Examples
        --------
        import asyncio

        from agenta import AsyncAgentaApi

        client = AsyncAgentaApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.apps.create_app(
                app_name="app_name",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_app(
            app_name=app_name,
            template_key=template_key,
            project_id=project_id,
            workspace_id=workspace_id,
            organization_id=organization_id,
            request_options=request_options,
        )
        return _response.data

    async def remove_app(
        self, app_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.Optional[typing.Any]:
        """
        Remove app, all its variant.

        Arguments:
            app -- App to remove

        Parameters
        ----------
        app_id : str

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

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

        Examples
        --------
        import asyncio

        from agenta import AsyncAgentaApi

        client = AsyncAgentaApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.apps.remove_app(
                app_id="app_id",
            )


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

    async def update_app(
        self,
        app_id: str,
        *,
        app_name: str,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpdateAppOutput:
        """
        Update an app for a user or organization.

        Args:
            app_id (str): The ID of the app.
            payload (UpdateApp): The payload containing the app name.

        Returns:
            UpdateAppOutput: The output containing the newly created app's ID and name.

        Raises:
            HTTPException: If there is an error creating the app or the user does not have permission to access the app.

        Parameters
        ----------
        app_id : str

        app_name : str

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

        Returns
        -------
        UpdateAppOutput
            Successful Response

        Examples
        --------
        import asyncio

        from agenta import AsyncAgentaApi

        client = AsyncAgentaApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.apps.update_app(
                app_id="app_id",
                app_name="app_name",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update_app(
            app_id, app_name=app_name, request_options=request_options
        )
        return _response.data

    async def add_variant_from_url(
        self,
        app_id: str,
        *,
        variant_name: str,
        url: str,
        commit_message: typing.Optional[str] = OMIT,
        base_name: typing.Optional[str] = OMIT,
        config_name: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Optional[typing.Any]:
        """
        Parameters
        ----------
        app_id : str

        variant_name : str

        url : str

        commit_message : typing.Optional[str]

        base_name : typing.Optional[str]

        config_name : typing.Optional[str]

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

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

        Examples
        --------
        import asyncio

        from agenta import AsyncAgentaApi

        client = AsyncAgentaApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.apps.add_variant_from_url(
                app_id="app_id",
                variant_name="variant_name",
                url="url",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.add_variant_from_url(
            app_id,
            variant_name=variant_name,
            url=url,
            commit_message=commit_message,
            base_name=base_name,
            config_name=config_name,
            request_options=request_options,
        )
        return _response.data

    async def add_variant_from_key(
        self,
        app_id: str,
        *,
        variant_name: str,
        key: str,
        commit_message: typing.Optional[str] = OMIT,
        base_name: typing.Optional[str] = OMIT,
        config_name: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Optional[typing.Any]:
        """
        Parameters
        ----------
        app_id : str

        variant_name : str

        key : str

        commit_message : typing.Optional[str]

        base_name : typing.Optional[str]

        config_name : typing.Optional[str]

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

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

        Examples
        --------
        import asyncio

        from agenta import AsyncAgentaApi

        client = AsyncAgentaApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.apps.add_variant_from_key(
                app_id="app_id",
                variant_name="variant_name",
                key="key",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.add_variant_from_key(
            app_id,
            variant_name=variant_name,
            key=key,
            commit_message=commit_message,
            base_name=base_name,
            config_name=config_name,
            request_options=request_options,
        )
        return _response.data

    async def list_environments(
        self, app_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[EnvironmentOutput]:
        """
        Retrieve a list of environments for a given app ID.

        Args:
            app_id (str): The ID of the app to retrieve environments for.

        Returns:
            List[EnvironmentOutput]: A list of environment objects.

        Parameters
        ----------
        app_id : str

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

        Returns
        -------
        typing.List[EnvironmentOutput]
            Successful Response

        Examples
        --------
        import asyncio

        from agenta import AsyncAgentaApi

        client = AsyncAgentaApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.apps.list_environments(
                app_id="app_id",
            )


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

    async def environment_revisions(
        self,
        app_id: str,
        environment_name: typing.Optional[typing.Any],
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EnvironmentOutputExtended:
        """
        Parameters
        ----------
        app_id : str

        environment_name : typing.Optional[typing.Any]

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

        Returns
        -------
        EnvironmentOutputExtended
            Successful Response

        Examples
        --------
        import asyncio

        from agenta import AsyncAgentaApi

        client = AsyncAgentaApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.apps.environment_revisions(
                app_id="app_id",
                environment_name={"key": "value"},
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.environment_revisions(
            app_id, environment_name, request_options=request_options
        )
        return _response.data
