# 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_response import DeleteResponse
from ..types.namespace import Namespace
from ..types.slug_availability_response import SlugAvailabilityResponse
from .raw_client import AsyncRawNamespacesClient, RawNamespacesClient

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


class NamespacesClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawNamespacesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawNamespacesClient
        """
        return self._raw_client

    def list(
        self,
        *,
        org_id: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        page_number: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[Namespace]:
        """
        List all namespaces the user has access to, optionally filtered by org.

        Parameters
        ----------
        org_id : typing.Optional[str]
            Filter by owner organization ID

        limit : typing.Optional[int]
            Maximum number of results

        page_number : typing.Optional[int]
            Page number

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

        Returns
        -------
        typing.List[Namespace]
            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.namespaces.list()
        """
        _response = self._raw_client.list(
            org_id=org_id, limit=limit, page_number=page_number, request_options=request_options
        )
        return _response.data

    def create(
        self, *, name: str, owner_org_id: str, slug: str, request_options: typing.Optional[RequestOptions] = None
    ) -> Namespace:
        """
        Create a new namespace for multi-tenant isolation.

        Parameters
        ----------
        name : str
            Human-readable name.

        owner_org_id : str
            WorkOS organization ID that owns this namespace.

        slug : str
            URL-friendly unique identifier (lowercase alphanumeric and hyphens).

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

        Returns
        -------
        Namespace
            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.namespaces.create(
            name="name",
            owner_org_id="owner_org_id",
            slug="slug",
        )
        """
        _response = self._raw_client.create(
            name=name, owner_org_id=owner_org_id, slug=slug, request_options=request_options
        )
        return _response.data

    def check_slug_availability(
        self, slug: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> SlugAvailabilityResponse:
        """
        Check if a namespace slug is available for use.

        Parameters
        ----------
        slug : str

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

        Returns
        -------
        SlugAvailabilityResponse
            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.namespaces.check_slug_availability(
            slug="slug",
        )
        """
        _response = self._raw_client.check_slug_availability(slug, request_options=request_options)
        return _response.data

    def retrieve_by_slug(self, slug: str, *, request_options: typing.Optional[RequestOptions] = None) -> Namespace:
        """
        Get a namespace by its slug.

        Parameters
        ----------
        slug : str

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

        Returns
        -------
        Namespace
            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.namespaces.retrieve_by_slug(
            slug="slug",
        )
        """
        _response = self._raw_client.retrieve_by_slug(slug, request_options=request_options)
        return _response.data

    def retrieve(self, namespace_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> Namespace:
        """
        Get a namespace by ID.

        Parameters
        ----------
        namespace_id : str

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

        Returns
        -------
        Namespace
            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.namespaces.retrieve(
            namespace_id="namespace_id",
        )
        """
        _response = self._raw_client.retrieve(namespace_id, request_options=request_options)
        return _response.data

    def delete(self, namespace_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> DeleteResponse:
        """
        Delete a namespace (must be empty).

        Parameters
        ----------
        namespace_id : str

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

        Returns
        -------
        DeleteResponse
            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.namespaces.delete(
            namespace_id="namespace_id",
        )
        """
        _response = self._raw_client.delete(namespace_id, request_options=request_options)
        return _response.data

    def update(
        self,
        namespace_id: str,
        *,
        name: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Namespace:
        """
        Update a namespace's properties.

        Parameters
        ----------
        namespace_id : str

        name : typing.Optional[str]
            Human-readable name.

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

        Returns
        -------
        Namespace
            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.namespaces.update(
            namespace_id="namespace_id",
        )
        """
        _response = self._raw_client.update(namespace_id, name=name, request_options=request_options)
        return _response.data

    def retry_provisioning(
        self,
        namespace_id: str,
        *,
        force: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Namespace:
        """
        Retry provisioning for a namespace that failed or is stuck.

        Parameters
        ----------
        namespace_id : str

        force : typing.Optional[bool]
            Force retry even if status is PENDING (for stuck namespaces)

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

        Returns
        -------
        Namespace
            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.namespaces.retry_provisioning(
            namespace_id="namespace_id",
        )
        """
        _response = self._raw_client.retry_provisioning(namespace_id, force=force, request_options=request_options)
        return _response.data


class AsyncNamespacesClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawNamespacesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawNamespacesClient
        """
        return self._raw_client

    async def list(
        self,
        *,
        org_id: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        page_number: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[Namespace]:
        """
        List all namespaces the user has access to, optionally filtered by org.

        Parameters
        ----------
        org_id : typing.Optional[str]
            Filter by owner organization ID

        limit : typing.Optional[int]
            Maximum number of results

        page_number : typing.Optional[int]
            Page number

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

        Returns
        -------
        typing.List[Namespace]
            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.namespaces.list()


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

    async def create(
        self, *, name: str, owner_org_id: str, slug: str, request_options: typing.Optional[RequestOptions] = None
    ) -> Namespace:
        """
        Create a new namespace for multi-tenant isolation.

        Parameters
        ----------
        name : str
            Human-readable name.

        owner_org_id : str
            WorkOS organization ID that owns this namespace.

        slug : str
            URL-friendly unique identifier (lowercase alphanumeric and hyphens).

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

        Returns
        -------
        Namespace
            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.namespaces.create(
                name="name",
                owner_org_id="owner_org_id",
                slug="slug",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create(
            name=name, owner_org_id=owner_org_id, slug=slug, request_options=request_options
        )
        return _response.data

    async def check_slug_availability(
        self, slug: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> SlugAvailabilityResponse:
        """
        Check if a namespace slug is available for use.

        Parameters
        ----------
        slug : str

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

        Returns
        -------
        SlugAvailabilityResponse
            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.namespaces.check_slug_availability(
                slug="slug",
            )


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

    async def retrieve_by_slug(
        self, slug: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> Namespace:
        """
        Get a namespace by its slug.

        Parameters
        ----------
        slug : str

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

        Returns
        -------
        Namespace
            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.namespaces.retrieve_by_slug(
                slug="slug",
            )


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

    async def retrieve(
        self, namespace_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> Namespace:
        """
        Get a namespace by ID.

        Parameters
        ----------
        namespace_id : str

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

        Returns
        -------
        Namespace
            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.namespaces.retrieve(
                namespace_id="namespace_id",
            )


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

    async def delete(
        self, namespace_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DeleteResponse:
        """
        Delete a namespace (must be empty).

        Parameters
        ----------
        namespace_id : str

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

        Returns
        -------
        DeleteResponse
            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.namespaces.delete(
                namespace_id="namespace_id",
            )


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

    async def update(
        self,
        namespace_id: str,
        *,
        name: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Namespace:
        """
        Update a namespace's properties.

        Parameters
        ----------
        namespace_id : str

        name : typing.Optional[str]
            Human-readable name.

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

        Returns
        -------
        Namespace
            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.namespaces.update(
                namespace_id="namespace_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update(namespace_id, name=name, request_options=request_options)
        return _response.data

    async def retry_provisioning(
        self,
        namespace_id: str,
        *,
        force: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Namespace:
        """
        Retry provisioning for a namespace that failed or is stuck.

        Parameters
        ----------
        namespace_id : str

        force : typing.Optional[bool]
            Force retry even if status is PENDING (for stuck namespaces)

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

        Returns
        -------
        Namespace
            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.namespaces.retry_provisioning(
                namespace_id="namespace_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.retry_provisioning(
            namespace_id, force=force, request_options=request_options
        )
        return _response.data
