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

import os
import typing

import httpx
from .alerts.client import AlertsClient, AsyncAlertsClient
from .application_versions.client import ApplicationVersionsClient, AsyncApplicationVersionsClient
from .applications.client import ApplicationsClient, AsyncApplicationsClient
from .artifact_versions.client import ArtifactVersionsClient, AsyncArtifactVersionsClient
from .artifacts.client import ArtifactsClient, AsyncArtifactsClient
from .clusters.client import AsyncClustersClient, ClustersClient
from .core.api_error import ApiError
from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from .core.request_options import RequestOptions
from .data_directories.client import AsyncDataDirectoriesClient, DataDirectoriesClient
from .environments.client import AsyncEnvironmentsClient, EnvironmentsClient
from .events.client import AsyncEventsClient, EventsClient
from .internal.client import AsyncInternalClient, InternalClient
from .jobs.client import AsyncJobsClient, JobsClient
from .logs.client import AsyncLogsClient, LogsClient
from .ml_repos.client import AsyncMlReposClient, MlReposClient
from .model_versions.client import AsyncModelVersionsClient, ModelVersionsClient
from .models.client import AsyncModelsClient, ModelsClient
from .personal_access_tokens.client import AsyncPersonalAccessTokensClient, PersonalAccessTokensClient
from .prompt_versions.client import AsyncPromptVersionsClient, PromptVersionsClient
from .prompts.client import AsyncPromptsClient, PromptsClient
from .raw_base_client import AsyncRawBaseTrueFoundry, RawBaseTrueFoundry
from .secret_groups.client import AsyncSecretGroupsClient, SecretGroupsClient
from .secrets.client import AsyncSecretsClient, SecretsClient
from .teams.client import AsyncTeamsClient, TeamsClient
from .types.true_foundry_apply_request_manifest import TrueFoundryApplyRequestManifest
from .types.true_foundry_apply_response import TrueFoundryApplyResponse
from .types.true_foundry_delete_request_manifest import TrueFoundryDeleteRequestManifest
from .users.client import AsyncUsersClient, UsersClient
from .virtual_accounts.client import AsyncVirtualAccountsClient, VirtualAccountsClient
from .workspaces.client import AsyncWorkspacesClient, WorkspacesClient

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


class BaseTrueFoundry:
    """
    Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions.

    Parameters
    ----------
    base_url : str
        The base url to use for requests from the client.

    api_key : typing.Optional[typing.Union[str, typing.Callable[[], str]]]
    headers : typing.Optional[typing.Dict[str, str]]
        Additional headers to send with every request.

    timeout : typing.Optional[float]
        The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.

    follow_redirects : typing.Optional[bool]
        Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.

    httpx_client : typing.Optional[httpx.Client]
        The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.

    Examples
    --------
    from truefoundry_sdk import TrueFoundry

    client = TrueFoundry(
        api_key="YOUR_API_KEY",
        base_url="https://yourhost.com/path/to/api",
    )
    """

    def __init__(
        self,
        *,
        base_url: str,
        api_key: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = os.getenv("TFY_API_KEY"),
        headers: typing.Optional[typing.Dict[str, str]] = None,
        timeout: typing.Optional[float] = None,
        follow_redirects: typing.Optional[bool] = True,
        httpx_client: typing.Optional[httpx.Client] = None,
    ):
        _defaulted_timeout = (
            timeout if timeout is not None else 60 if httpx_client is None else httpx_client.timeout.read
        )
        if api_key is None:
            raise ApiError(body="The client must be instantiated be either passing in api_key or setting TFY_API_KEY")
        self._client_wrapper = SyncClientWrapper(
            base_url=base_url,
            api_key=api_key,
            headers=headers,
            httpx_client=httpx_client
            if httpx_client is not None
            else httpx.Client(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
            if follow_redirects is not None
            else httpx.Client(timeout=_defaulted_timeout),
            timeout=_defaulted_timeout,
        )
        self._raw_client = RawBaseTrueFoundry(client_wrapper=self._client_wrapper)
        self.internal = InternalClient(client_wrapper=self._client_wrapper)
        self.users = UsersClient(client_wrapper=self._client_wrapper)
        self.teams = TeamsClient(client_wrapper=self._client_wrapper)
        self.personal_access_tokens = PersonalAccessTokensClient(client_wrapper=self._client_wrapper)
        self.virtual_accounts = VirtualAccountsClient(client_wrapper=self._client_wrapper)
        self.secrets = SecretsClient(client_wrapper=self._client_wrapper)
        self.secret_groups = SecretGroupsClient(client_wrapper=self._client_wrapper)
        self.clusters = ClustersClient(client_wrapper=self._client_wrapper)
        self.environments = EnvironmentsClient(client_wrapper=self._client_wrapper)
        self.applications = ApplicationsClient(client_wrapper=self._client_wrapper)
        self.application_versions = ApplicationVersionsClient(client_wrapper=self._client_wrapper)
        self.jobs = JobsClient(client_wrapper=self._client_wrapper)
        self.workspaces = WorkspacesClient(client_wrapper=self._client_wrapper)
        self.events = EventsClient(client_wrapper=self._client_wrapper)
        self.alerts = AlertsClient(client_wrapper=self._client_wrapper)
        self.logs = LogsClient(client_wrapper=self._client_wrapper)
        self.ml_repos = MlReposClient(client_wrapper=self._client_wrapper)
        self.artifacts = ArtifactsClient(client_wrapper=self._client_wrapper)
        self.prompts = PromptsClient(client_wrapper=self._client_wrapper)
        self.models = ModelsClient(client_wrapper=self._client_wrapper)
        self.artifact_versions = ArtifactVersionsClient(client_wrapper=self._client_wrapper)
        self.model_versions = ModelVersionsClient(client_wrapper=self._client_wrapper)
        self.prompt_versions = PromptVersionsClient(client_wrapper=self._client_wrapper)
        self.data_directories = DataDirectoriesClient(client_wrapper=self._client_wrapper)

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

        Returns
        -------
        RawBaseTrueFoundry
        """
        return self._raw_client

    def apply(
        self,
        *,
        manifest: TrueFoundryApplyRequestManifest,
        dry_run: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TrueFoundryApplyResponse:
        """
        Applies a given manifest to create or update resources of specific types, such as provider-account, cluster, workspace, or ml-repo.

        Parameters
        ----------
        manifest : TrueFoundryApplyRequestManifest
            manifest of the resource to be created or updated

        dry_run : typing.Optional[bool]
            Dry run the apply operation without actually applying

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

        Returns
        -------
        TrueFoundryApplyResponse
            The resource has been successfully created or updated.

        Examples
        --------
        from truefoundry_sdk import Collaborator, MlRepoManifest, TrueFoundry

        client = TrueFoundry(
            api_key="YOUR_API_KEY",
            base_url="https://yourhost.com/path/to/api",
        )
        client.apply(
            manifest=MlRepoManifest(
                name="name",
                storage_integration_fqn="storage_integration_fqn",
                collaborators=[
                    Collaborator(
                        subject="subject",
                        role_id="role_id",
                    )
                ],
            ),
        )
        """
        _response = self._raw_client.apply(manifest=manifest, dry_run=dry_run, request_options=request_options)
        return _response.data

    def delete(
        self, *, manifest: TrueFoundryDeleteRequestManifest, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Deletes resources of specific types, such as provider-account, cluster, workspace, or application.

        Parameters
        ----------
        manifest : TrueFoundryDeleteRequestManifest
            manifest of the resource to be deleted

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

        Returns
        -------
        None

        Examples
        --------
        from truefoundry_sdk import Collaborator, MlRepoManifest, TrueFoundry

        client = TrueFoundry(
            api_key="YOUR_API_KEY",
            base_url="https://yourhost.com/path/to/api",
        )
        client.delete(
            manifest=MlRepoManifest(
                name="name",
                storage_integration_fqn="storage_integration_fqn",
                collaborators=[
                    Collaborator(
                        subject="subject",
                        role_id="role_id",
                    )
                ],
            ),
        )
        """
        _response = self._raw_client.delete(manifest=manifest, request_options=request_options)
        return _response.data


class AsyncBaseTrueFoundry:
    """
    Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions.

    Parameters
    ----------
    base_url : str
        The base url to use for requests from the client.

    api_key : typing.Optional[typing.Union[str, typing.Callable[[], str]]]
    headers : typing.Optional[typing.Dict[str, str]]
        Additional headers to send with every request.

    timeout : typing.Optional[float]
        The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.

    follow_redirects : typing.Optional[bool]
        Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.

    httpx_client : typing.Optional[httpx.AsyncClient]
        The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.

    Examples
    --------
    from truefoundry_sdk import AsyncTrueFoundry

    client = AsyncTrueFoundry(
        api_key="YOUR_API_KEY",
        base_url="https://yourhost.com/path/to/api",
    )
    """

    def __init__(
        self,
        *,
        base_url: str,
        api_key: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = os.getenv("TFY_API_KEY"),
        headers: typing.Optional[typing.Dict[str, str]] = None,
        timeout: typing.Optional[float] = None,
        follow_redirects: typing.Optional[bool] = True,
        httpx_client: typing.Optional[httpx.AsyncClient] = None,
    ):
        _defaulted_timeout = (
            timeout if timeout is not None else 60 if httpx_client is None else httpx_client.timeout.read
        )
        if api_key is None:
            raise ApiError(body="The client must be instantiated be either passing in api_key or setting TFY_API_KEY")
        self._client_wrapper = AsyncClientWrapper(
            base_url=base_url,
            api_key=api_key,
            headers=headers,
            httpx_client=httpx_client
            if httpx_client is not None
            else httpx.AsyncClient(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
            if follow_redirects is not None
            else httpx.AsyncClient(timeout=_defaulted_timeout),
            timeout=_defaulted_timeout,
        )
        self._raw_client = AsyncRawBaseTrueFoundry(client_wrapper=self._client_wrapper)
        self.internal = AsyncInternalClient(client_wrapper=self._client_wrapper)
        self.users = AsyncUsersClient(client_wrapper=self._client_wrapper)
        self.teams = AsyncTeamsClient(client_wrapper=self._client_wrapper)
        self.personal_access_tokens = AsyncPersonalAccessTokensClient(client_wrapper=self._client_wrapper)
        self.virtual_accounts = AsyncVirtualAccountsClient(client_wrapper=self._client_wrapper)
        self.secrets = AsyncSecretsClient(client_wrapper=self._client_wrapper)
        self.secret_groups = AsyncSecretGroupsClient(client_wrapper=self._client_wrapper)
        self.clusters = AsyncClustersClient(client_wrapper=self._client_wrapper)
        self.environments = AsyncEnvironmentsClient(client_wrapper=self._client_wrapper)
        self.applications = AsyncApplicationsClient(client_wrapper=self._client_wrapper)
        self.application_versions = AsyncApplicationVersionsClient(client_wrapper=self._client_wrapper)
        self.jobs = AsyncJobsClient(client_wrapper=self._client_wrapper)
        self.workspaces = AsyncWorkspacesClient(client_wrapper=self._client_wrapper)
        self.events = AsyncEventsClient(client_wrapper=self._client_wrapper)
        self.alerts = AsyncAlertsClient(client_wrapper=self._client_wrapper)
        self.logs = AsyncLogsClient(client_wrapper=self._client_wrapper)
        self.ml_repos = AsyncMlReposClient(client_wrapper=self._client_wrapper)
        self.artifacts = AsyncArtifactsClient(client_wrapper=self._client_wrapper)
        self.prompts = AsyncPromptsClient(client_wrapper=self._client_wrapper)
        self.models = AsyncModelsClient(client_wrapper=self._client_wrapper)
        self.artifact_versions = AsyncArtifactVersionsClient(client_wrapper=self._client_wrapper)
        self.model_versions = AsyncModelVersionsClient(client_wrapper=self._client_wrapper)
        self.prompt_versions = AsyncPromptVersionsClient(client_wrapper=self._client_wrapper)
        self.data_directories = AsyncDataDirectoriesClient(client_wrapper=self._client_wrapper)

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

        Returns
        -------
        AsyncRawBaseTrueFoundry
        """
        return self._raw_client

    async def apply(
        self,
        *,
        manifest: TrueFoundryApplyRequestManifest,
        dry_run: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> TrueFoundryApplyResponse:
        """
        Applies a given manifest to create or update resources of specific types, such as provider-account, cluster, workspace, or ml-repo.

        Parameters
        ----------
        manifest : TrueFoundryApplyRequestManifest
            manifest of the resource to be created or updated

        dry_run : typing.Optional[bool]
            Dry run the apply operation without actually applying

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

        Returns
        -------
        TrueFoundryApplyResponse
            The resource has been successfully created or updated.

        Examples
        --------
        import asyncio

        from truefoundry_sdk import AsyncTrueFoundry, Collaborator, MlRepoManifest

        client = AsyncTrueFoundry(
            api_key="YOUR_API_KEY",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.apply(
                manifest=MlRepoManifest(
                    name="name",
                    storage_integration_fqn="storage_integration_fqn",
                    collaborators=[
                        Collaborator(
                            subject="subject",
                            role_id="role_id",
                        )
                    ],
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.apply(manifest=manifest, dry_run=dry_run, request_options=request_options)
        return _response.data

    async def delete(
        self, *, manifest: TrueFoundryDeleteRequestManifest, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Deletes resources of specific types, such as provider-account, cluster, workspace, or application.

        Parameters
        ----------
        manifest : TrueFoundryDeleteRequestManifest
            manifest of the resource to be deleted

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

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from truefoundry_sdk import AsyncTrueFoundry, Collaborator, MlRepoManifest

        client = AsyncTrueFoundry(
            api_key="YOUR_API_KEY",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.delete(
                manifest=MlRepoManifest(
                    name="name",
                    storage_integration_fqn="storage_integration_fqn",
                    collaborators=[
                        Collaborator(
                            subject="subject",
                            role_id="role_id",
                        )
                    ],
                ),
            )


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