# 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.registry_auth_response import RegistryAuthResponse
from .raw_client import AsyncRawRegistryClient, RawRegistryClient


class RegistryClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawRegistryClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawRegistryClient
        """
        return self._raw_client

    def auth(self, *, namespace: str, request_options: typing.Optional[RequestOptions] = None) -> RegistryAuthResponse:
        """
        Get short-lived credentials for pushing images to a namespace's registry.

            Each namespace has its own isolated registry repository. The token returned
            can ONLY push images to the specified namespace's repository.

            The CLI uses this endpoint to authenticate with Docker before pushing
            agent images. Returns a token valid for approximately 1 hour.

            **Usage with Docker:**
            ```bash
            docker login {registry_url} -u {username} -p {token}
            docker push {registry_url}/{repository}/{agent}:{tag}
            ```

        Parameters
        ----------
        namespace : str
            Target namespace slug for the image push

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

        Returns
        -------
        RegistryAuthResponse
            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.registry.auth(
            namespace="acme",
        )
        """
        _response = self._raw_client.auth(namespace=namespace, request_options=request_options)
        return _response.data


class AsyncRegistryClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawRegistryClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawRegistryClient
        """
        return self._raw_client

    async def auth(
        self, *, namespace: str, request_options: typing.Optional[RequestOptions] = None
    ) -> RegistryAuthResponse:
        """
        Get short-lived credentials for pushing images to a namespace's registry.

            Each namespace has its own isolated registry repository. The token returned
            can ONLY push images to the specified namespace's repository.

            The CLI uses this endpoint to authenticate with Docker before pushing
            agent images. Returns a token valid for approximately 1 hour.

            **Usage with Docker:**
            ```bash
            docker login {registry_url} -u {username} -p {token}
            docker push {registry_url}/{repository}/{agent}:{tag}
            ```

        Parameters
        ----------
        namespace : str
            Target namespace slug for the image push

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

        Returns
        -------
        RegistryAuthResponse
            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.registry.auth(
                namespace="acme",
            )


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