# 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.delete_env_var_response import DeleteEnvVarResponse
from ....types.deployed_secrets_response import DeployedSecretsResponse
from ....types.env_var_list_response import EnvVarListResponse
from ....types.env_var_value import EnvVarValue
from ....types.set_env_var_response import SetEnvVarResponse
from .raw_client import AsyncRawSecretsClient, RawSecretsClient

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


class SecretsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawSecretsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawSecretsClient
        """
        return self._raw_client

    def list(
        self,
        namespace_slug: str,
        agent_name: str,
        env_name: str,
        *,
        include_values: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EnvVarListResponse:
        """
        List PENDING secrets for an environment (from EnvVar table).

            This is what will be used on next deploy.
            For deployed state, use GET /agents/{namespace_slug}/{agent_name}/environments/{env}/secrets/deployed

            Note: is_secret=True values are NEVER returned, only non-secrets when include_values=True.

        Parameters
        ----------
        namespace_slug : str

        agent_name : str

        env_name : str

        include_values : typing.Optional[bool]
            Include values for non-secrets (is_secret=False only)

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

        Returns
        -------
        EnvVarListResponse
            Successful Response

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.agents.environments.secrets.list(
            namespace_slug="namespace_slug",
            agent_name="agent_name",
            env_name="env_name",
        )
        """
        _response = self._raw_client.list(
            namespace_slug, agent_name, env_name, include_values=include_values, request_options=request_options
        )
        return _response.data

    def set(
        self,
        namespace_slug: str,
        agent_name: str,
        env_name: str,
        *,
        secrets: typing.Dict[str, EnvVarValue],
        redeploy: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SetEnvVarResponse:
        """
        Set one or more secrets/config values.

            If redeploy=True (default) and environment has active deployment,
            triggers redeploy with same image but new secrets_snapshot.

        Parameters
        ----------
        namespace_slug : str

        agent_name : str

        env_name : str

        secrets : typing.Dict[str, EnvVarValue]
            Dict of {key: {value, is_secret}} to set

        redeploy : typing.Optional[bool]
            If true and env has active deployment, trigger redeploy with new secrets

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

        Returns
        -------
        SetEnvVarResponse
            Successful Response

        Examples
        --------
        from terminaluse import EnvVarValue, TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.agents.environments.secrets.set(
            namespace_slug="namespace_slug",
            agent_name="agent_name",
            env_name="env_name",
            secrets={
                "key": EnvVarValue(
                    value="value",
                )
            },
        )
        """
        _response = self._raw_client.set(
            namespace_slug, agent_name, env_name, secrets=secrets, redeploy=redeploy, request_options=request_options
        )
        return _response.data

    def list_deployed(
        self,
        namespace_slug: str,
        agent_name: str,
        env_name: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DeployedSecretsResponse:
        """
        List DEPLOYED secrets for an environment (from Version.secrets_snapshot).

            This is what's currently running. May differ from pending state after rollback.
            Only returns keys, never actual values.

        Parameters
        ----------
        namespace_slug : str

        agent_name : str

        env_name : str

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

        Returns
        -------
        DeployedSecretsResponse
            Successful Response

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.agents.environments.secrets.list_deployed(
            namespace_slug="namespace_slug",
            agent_name="agent_name",
            env_name="env_name",
        )
        """
        _response = self._raw_client.list_deployed(
            namespace_slug, agent_name, env_name, request_options=request_options
        )
        return _response.data

    def delete(
        self,
        namespace_slug: str,
        agent_name: str,
        env_name: str,
        key: str,
        *,
        redeploy: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DeleteEnvVarResponse:
        """
        Delete a secret from an environment.

            If redeploy=True (default), triggers redeploy with updated secrets.

        Parameters
        ----------
        namespace_slug : str

        agent_name : str

        env_name : str

        key : str

        redeploy : typing.Optional[bool]
            If true, trigger redeploy after deletion

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

        Returns
        -------
        DeleteEnvVarResponse
            Successful Response

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.agents.environments.secrets.delete(
            namespace_slug="namespace_slug",
            agent_name="agent_name",
            env_name="env_name",
            key="key",
        )
        """
        _response = self._raw_client.delete(
            namespace_slug, agent_name, env_name, key, redeploy=redeploy, request_options=request_options
        )
        return _response.data


class AsyncSecretsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawSecretsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawSecretsClient
        """
        return self._raw_client

    async def list(
        self,
        namespace_slug: str,
        agent_name: str,
        env_name: str,
        *,
        include_values: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EnvVarListResponse:
        """
        List PENDING secrets for an environment (from EnvVar table).

            This is what will be used on next deploy.
            For deployed state, use GET /agents/{namespace_slug}/{agent_name}/environments/{env}/secrets/deployed

            Note: is_secret=True values are NEVER returned, only non-secrets when include_values=True.

        Parameters
        ----------
        namespace_slug : str

        agent_name : str

        env_name : str

        include_values : typing.Optional[bool]
            Include values for non-secrets (is_secret=False only)

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

        Returns
        -------
        EnvVarListResponse
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.agents.environments.secrets.list(
                namespace_slug="namespace_slug",
                agent_name="agent_name",
                env_name="env_name",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.list(
            namespace_slug, agent_name, env_name, include_values=include_values, request_options=request_options
        )
        return _response.data

    async def set(
        self,
        namespace_slug: str,
        agent_name: str,
        env_name: str,
        *,
        secrets: typing.Dict[str, EnvVarValue],
        redeploy: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SetEnvVarResponse:
        """
        Set one or more secrets/config values.

            If redeploy=True (default) and environment has active deployment,
            triggers redeploy with same image but new secrets_snapshot.

        Parameters
        ----------
        namespace_slug : str

        agent_name : str

        env_name : str

        secrets : typing.Dict[str, EnvVarValue]
            Dict of {key: {value, is_secret}} to set

        redeploy : typing.Optional[bool]
            If true and env has active deployment, trigger redeploy with new secrets

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

        Returns
        -------
        SetEnvVarResponse
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase, EnvVarValue

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.agents.environments.secrets.set(
                namespace_slug="namespace_slug",
                agent_name="agent_name",
                env_name="env_name",
                secrets={
                    "key": EnvVarValue(
                        value="value",
                    )
                },
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.set(
            namespace_slug, agent_name, env_name, secrets=secrets, redeploy=redeploy, request_options=request_options
        )
        return _response.data

    async def list_deployed(
        self,
        namespace_slug: str,
        agent_name: str,
        env_name: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DeployedSecretsResponse:
        """
        List DEPLOYED secrets for an environment (from Version.secrets_snapshot).

            This is what's currently running. May differ from pending state after rollback.
            Only returns keys, never actual values.

        Parameters
        ----------
        namespace_slug : str

        agent_name : str

        env_name : str

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

        Returns
        -------
        DeployedSecretsResponse
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.agents.environments.secrets.list_deployed(
                namespace_slug="namespace_slug",
                agent_name="agent_name",
                env_name="env_name",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.list_deployed(
            namespace_slug, agent_name, env_name, request_options=request_options
        )
        return _response.data

    async def delete(
        self,
        namespace_slug: str,
        agent_name: str,
        env_name: str,
        key: str,
        *,
        redeploy: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DeleteEnvVarResponse:
        """
        Delete a secret from an environment.

            If redeploy=True (default), triggers redeploy with updated secrets.

        Parameters
        ----------
        namespace_slug : str

        agent_name : str

        env_name : str

        key : str

        redeploy : typing.Optional[bool]
            If true, trigger redeploy after deletion

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

        Returns
        -------
        DeleteEnvVarResponse
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.agents.environments.secrets.delete(
                namespace_slug="namespace_slug",
                agent_name="agent_name",
                env_name="env_name",
                key="key",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.delete(
            namespace_slug, agent_name, env_name, key, redeploy=redeploy, request_options=request_options
        )
        return _response.data
