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

from __future__ import annotations

import typing

import httpx
from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from .environment import FrameioEnvironment

if typing.TYPE_CHECKING:
    from .account_permissions.client import AccountPermissionsClient, AsyncAccountPermissionsClient
    from .accounts.client import AccountsClient, AsyncAccountsClient
    from .comments.client import AsyncCommentsClient, CommentsClient
    from .files.client import AsyncFilesClient, FilesClient
    from .folders.client import AsyncFoldersClient, FoldersClient
    from .metadata.client import AsyncMetadataClient, MetadataClient
    from .metadata_fields.client import AsyncMetadataFieldsClient, MetadataFieldsClient
    from .project_permissions.client import AsyncProjectPermissionsClient, ProjectPermissionsClient
    from .projects.client import AsyncProjectsClient, ProjectsClient
    from .shares.client import AsyncSharesClient, SharesClient
    from .users.client import AsyncUsersClient, UsersClient
    from .version_stacks.client import AsyncVersionStacksClient, VersionStacksClient
    from .webhooks.client import AsyncWebhooksClient, WebhooksClient
    from .workspace_permissions.client import AsyncWorkspacePermissionsClient, WorkspacePermissionsClient
    from .workspaces.client import AsyncWorkspacesClient, WorkspacesClient


class Frameio:
    """
    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 : typing.Optional[str]
        The base url to use for requests from the client.

    environment : FrameioEnvironment
        The environment to use for requests from the client. from .environment import FrameioEnvironment



        Defaults to FrameioEnvironment.DEFAULT



    token : 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 frameio import Frameio

    client = Frameio(
        token="YOUR_TOKEN",
    )
    """

    def __init__(
        self,
        *,
        base_url: typing.Optional[str] = None,
        environment: FrameioEnvironment = FrameioEnvironment.DEFAULT,
        token: typing.Union[str, typing.Callable[[], str]],
        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
        )
        self._client_wrapper = SyncClientWrapper(
            base_url=_get_base_url(base_url=base_url, environment=environment),
            token=token,
            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._metadata_fields: typing.Optional[MetadataFieldsClient] = None
        self._project_permissions: typing.Optional[ProjectPermissionsClient] = None
        self._folders: typing.Optional[FoldersClient] = None
        self._version_stacks: typing.Optional[VersionStacksClient] = None
        self._account_permissions: typing.Optional[AccountPermissionsClient] = None
        self._accounts: typing.Optional[AccountsClient] = None
        self._comments: typing.Optional[CommentsClient] = None
        self._webhooks: typing.Optional[WebhooksClient] = None
        self._workspace_permissions: typing.Optional[WorkspacePermissionsClient] = None
        self._shares: typing.Optional[SharesClient] = None
        self._metadata: typing.Optional[MetadataClient] = None
        self._files: typing.Optional[FilesClient] = None
        self._users: typing.Optional[UsersClient] = None
        self._projects: typing.Optional[ProjectsClient] = None
        self._workspaces: typing.Optional[WorkspacesClient] = None

    @property
    def metadata_fields(self):
        if self._metadata_fields is None:
            from .metadata_fields.client import MetadataFieldsClient  # noqa: E402

            self._metadata_fields = MetadataFieldsClient(client_wrapper=self._client_wrapper)
        return self._metadata_fields

    @property
    def project_permissions(self):
        if self._project_permissions is None:
            from .project_permissions.client import ProjectPermissionsClient  # noqa: E402

            self._project_permissions = ProjectPermissionsClient(client_wrapper=self._client_wrapper)
        return self._project_permissions

    @property
    def folders(self):
        if self._folders is None:
            from .folders.client import FoldersClient  # noqa: E402

            self._folders = FoldersClient(client_wrapper=self._client_wrapper)
        return self._folders

    @property
    def version_stacks(self):
        if self._version_stacks is None:
            from .version_stacks.client import VersionStacksClient  # noqa: E402

            self._version_stacks = VersionStacksClient(client_wrapper=self._client_wrapper)
        return self._version_stacks

    @property
    def account_permissions(self):
        if self._account_permissions is None:
            from .account_permissions.client import AccountPermissionsClient  # noqa: E402

            self._account_permissions = AccountPermissionsClient(client_wrapper=self._client_wrapper)
        return self._account_permissions

    @property
    def accounts(self):
        if self._accounts is None:
            from .accounts.client import AccountsClient  # noqa: E402

            self._accounts = AccountsClient(client_wrapper=self._client_wrapper)
        return self._accounts

    @property
    def comments(self):
        if self._comments is None:
            from .comments.client import CommentsClient  # noqa: E402

            self._comments = CommentsClient(client_wrapper=self._client_wrapper)
        return self._comments

    @property
    def webhooks(self):
        if self._webhooks is None:
            from .webhooks.client import WebhooksClient  # noqa: E402

            self._webhooks = WebhooksClient(client_wrapper=self._client_wrapper)
        return self._webhooks

    @property
    def workspace_permissions(self):
        if self._workspace_permissions is None:
            from .workspace_permissions.client import WorkspacePermissionsClient  # noqa: E402

            self._workspace_permissions = WorkspacePermissionsClient(client_wrapper=self._client_wrapper)
        return self._workspace_permissions

    @property
    def shares(self):
        if self._shares is None:
            from .shares.client import SharesClient  # noqa: E402

            self._shares = SharesClient(client_wrapper=self._client_wrapper)
        return self._shares

    @property
    def metadata(self):
        if self._metadata is None:
            from .metadata.client import MetadataClient  # noqa: E402

            self._metadata = MetadataClient(client_wrapper=self._client_wrapper)
        return self._metadata

    @property
    def files(self):
        if self._files is None:
            from .files.client import FilesClient  # noqa: E402

            self._files = FilesClient(client_wrapper=self._client_wrapper)
        return self._files

    @property
    def users(self):
        if self._users is None:
            from .users.client import UsersClient  # noqa: E402

            self._users = UsersClient(client_wrapper=self._client_wrapper)
        return self._users

    @property
    def projects(self):
        if self._projects is None:
            from .projects.client import ProjectsClient  # noqa: E402

            self._projects = ProjectsClient(client_wrapper=self._client_wrapper)
        return self._projects

    @property
    def workspaces(self):
        if self._workspaces is None:
            from .workspaces.client import WorkspacesClient  # noqa: E402

            self._workspaces = WorkspacesClient(client_wrapper=self._client_wrapper)
        return self._workspaces


class AsyncFrameio:
    """
    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 : typing.Optional[str]
        The base url to use for requests from the client.

    environment : FrameioEnvironment
        The environment to use for requests from the client. from .environment import FrameioEnvironment



        Defaults to FrameioEnvironment.DEFAULT



    token : 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 frameio import AsyncFrameio

    client = AsyncFrameio(
        token="YOUR_TOKEN",
    )
    """

    def __init__(
        self,
        *,
        base_url: typing.Optional[str] = None,
        environment: FrameioEnvironment = FrameioEnvironment.DEFAULT,
        token: typing.Union[str, typing.Callable[[], str]],
        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
        )
        self._client_wrapper = AsyncClientWrapper(
            base_url=_get_base_url(base_url=base_url, environment=environment),
            token=token,
            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._metadata_fields: typing.Optional[AsyncMetadataFieldsClient] = None
        self._project_permissions: typing.Optional[AsyncProjectPermissionsClient] = None
        self._folders: typing.Optional[AsyncFoldersClient] = None
        self._version_stacks: typing.Optional[AsyncVersionStacksClient] = None
        self._account_permissions: typing.Optional[AsyncAccountPermissionsClient] = None
        self._accounts: typing.Optional[AsyncAccountsClient] = None
        self._comments: typing.Optional[AsyncCommentsClient] = None
        self._webhooks: typing.Optional[AsyncWebhooksClient] = None
        self._workspace_permissions: typing.Optional[AsyncWorkspacePermissionsClient] = None
        self._shares: typing.Optional[AsyncSharesClient] = None
        self._metadata: typing.Optional[AsyncMetadataClient] = None
        self._files: typing.Optional[AsyncFilesClient] = None
        self._users: typing.Optional[AsyncUsersClient] = None
        self._projects: typing.Optional[AsyncProjectsClient] = None
        self._workspaces: typing.Optional[AsyncWorkspacesClient] = None

    @property
    def metadata_fields(self):
        if self._metadata_fields is None:
            from .metadata_fields.client import AsyncMetadataFieldsClient  # noqa: E402

            self._metadata_fields = AsyncMetadataFieldsClient(client_wrapper=self._client_wrapper)
        return self._metadata_fields

    @property
    def project_permissions(self):
        if self._project_permissions is None:
            from .project_permissions.client import AsyncProjectPermissionsClient  # noqa: E402

            self._project_permissions = AsyncProjectPermissionsClient(client_wrapper=self._client_wrapper)
        return self._project_permissions

    @property
    def folders(self):
        if self._folders is None:
            from .folders.client import AsyncFoldersClient  # noqa: E402

            self._folders = AsyncFoldersClient(client_wrapper=self._client_wrapper)
        return self._folders

    @property
    def version_stacks(self):
        if self._version_stacks is None:
            from .version_stacks.client import AsyncVersionStacksClient  # noqa: E402

            self._version_stacks = AsyncVersionStacksClient(client_wrapper=self._client_wrapper)
        return self._version_stacks

    @property
    def account_permissions(self):
        if self._account_permissions is None:
            from .account_permissions.client import AsyncAccountPermissionsClient  # noqa: E402

            self._account_permissions = AsyncAccountPermissionsClient(client_wrapper=self._client_wrapper)
        return self._account_permissions

    @property
    def accounts(self):
        if self._accounts is None:
            from .accounts.client import AsyncAccountsClient  # noqa: E402

            self._accounts = AsyncAccountsClient(client_wrapper=self._client_wrapper)
        return self._accounts

    @property
    def comments(self):
        if self._comments is None:
            from .comments.client import AsyncCommentsClient  # noqa: E402

            self._comments = AsyncCommentsClient(client_wrapper=self._client_wrapper)
        return self._comments

    @property
    def webhooks(self):
        if self._webhooks is None:
            from .webhooks.client import AsyncWebhooksClient  # noqa: E402

            self._webhooks = AsyncWebhooksClient(client_wrapper=self._client_wrapper)
        return self._webhooks

    @property
    def workspace_permissions(self):
        if self._workspace_permissions is None:
            from .workspace_permissions.client import AsyncWorkspacePermissionsClient  # noqa: E402

            self._workspace_permissions = AsyncWorkspacePermissionsClient(client_wrapper=self._client_wrapper)
        return self._workspace_permissions

    @property
    def shares(self):
        if self._shares is None:
            from .shares.client import AsyncSharesClient  # noqa: E402

            self._shares = AsyncSharesClient(client_wrapper=self._client_wrapper)
        return self._shares

    @property
    def metadata(self):
        if self._metadata is None:
            from .metadata.client import AsyncMetadataClient  # noqa: E402

            self._metadata = AsyncMetadataClient(client_wrapper=self._client_wrapper)
        return self._metadata

    @property
    def files(self):
        if self._files is None:
            from .files.client import AsyncFilesClient  # noqa: E402

            self._files = AsyncFilesClient(client_wrapper=self._client_wrapper)
        return self._files

    @property
    def users(self):
        if self._users is None:
            from .users.client import AsyncUsersClient  # noqa: E402

            self._users = AsyncUsersClient(client_wrapper=self._client_wrapper)
        return self._users

    @property
    def projects(self):
        if self._projects is None:
            from .projects.client import AsyncProjectsClient  # noqa: E402

            self._projects = AsyncProjectsClient(client_wrapper=self._client_wrapper)
        return self._projects

    @property
    def workspaces(self):
        if self._workspaces is None:
            from .workspaces.client import AsyncWorkspacesClient  # noqa: E402

            self._workspaces = AsyncWorkspacesClient(client_wrapper=self._client_wrapper)
        return self._workspaces


def _get_base_url(*, base_url: typing.Optional[str] = None, environment: FrameioEnvironment) -> str:
    if base_url is not None:
        return base_url
    elif environment is not None:
        return environment.value
    else:
        raise Exception("Please pass in either base_url or environment to construct the client")
