# 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.environment_deployment_config import EnvironmentDeploymentConfig
from ..types.src_handlers_get_workflow_environments_response import SrcHandlersGetWorkflowEnvironmentsResponse
from ..types.src_handlers_update_workflow_environment_response import SrcHandlersUpdateWorkflowEnvironmentResponse
from .raw_client import AsyncRawEnvironmentsClient, RawEnvironmentsClient

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


class EnvironmentsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawEnvironmentsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawEnvironmentsClient
        """
        return self._raw_client

    def list(
        self, workflow_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> SrcHandlersGetWorkflowEnvironmentsResponse:
        """
        List all environments for a workflow in the organization

        Parameters
        ----------
        workflow_id : str

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

        Returns
        -------
        SrcHandlersGetWorkflowEnvironmentsResponse
            Successful Response

        Examples
        --------
        from scoutos import Scout

        client = Scout(
            api_key="YOUR_API_KEY",
        )
        client.environments.list(
            workflow_id="workflow_id",
        )
        """
        _response = self._raw_client.list(workflow_id, request_options=request_options)
        return _response.data

    def update(
        self,
        workflow_id: str,
        environment_id: str,
        *,
        name: str,
        description: str,
        deployments: typing.Sequence[EnvironmentDeploymentConfig],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SrcHandlersUpdateWorkflowEnvironmentResponse:
        """
        Update deployments within a workflow environment

        Parameters
        ----------
        workflow_id : str

        environment_id : str

        name : str

        description : str

        deployments : typing.Sequence[EnvironmentDeploymentConfig]

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

        Returns
        -------
        SrcHandlersUpdateWorkflowEnvironmentResponse
            Successful Response

        Examples
        --------
        from scoutos import EnvironmentDeploymentConfig, Scout

        client = Scout(
            api_key="YOUR_API_KEY",
        )
        client.environments.update(
            workflow_id="workflow_id",
            environment_id="environment_id",
            name="name",
            description="description",
            deployments=[
                EnvironmentDeploymentConfig(
                    revision_lookup="latest",
                )
            ],
        )
        """
        _response = self._raw_client.update(
            workflow_id,
            environment_id,
            name=name,
            description=description,
            deployments=deployments,
            request_options=request_options,
        )
        return _response.data


class AsyncEnvironmentsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawEnvironmentsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawEnvironmentsClient
        """
        return self._raw_client

    async def list(
        self, workflow_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> SrcHandlersGetWorkflowEnvironmentsResponse:
        """
        List all environments for a workflow in the organization

        Parameters
        ----------
        workflow_id : str

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

        Returns
        -------
        SrcHandlersGetWorkflowEnvironmentsResponse
            Successful Response

        Examples
        --------
        import asyncio

        from scoutos import AsyncScout

        client = AsyncScout(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.environments.list(
                workflow_id="workflow_id",
            )


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

    async def update(
        self,
        workflow_id: str,
        environment_id: str,
        *,
        name: str,
        description: str,
        deployments: typing.Sequence[EnvironmentDeploymentConfig],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SrcHandlersUpdateWorkflowEnvironmentResponse:
        """
        Update deployments within a workflow environment

        Parameters
        ----------
        workflow_id : str

        environment_id : str

        name : str

        description : str

        deployments : typing.Sequence[EnvironmentDeploymentConfig]

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

        Returns
        -------
        SrcHandlersUpdateWorkflowEnvironmentResponse
            Successful Response

        Examples
        --------
        import asyncio

        from scoutos import AsyncScout, EnvironmentDeploymentConfig

        client = AsyncScout(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.environments.update(
                workflow_id="workflow_id",
                environment_id="environment_id",
                name="name",
                description="description",
                deployments=[
                    EnvironmentDeploymentConfig(
                        revision_lookup="latest",
                    )
                ],
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update(
            workflow_id,
            environment_id,
            name=name,
            description=description,
            deployments=deployments,
            request_options=request_options,
        )
        return _response.data
