# 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.build_prepare_response import BuildPrepareResponse
from ..types.build_status_response import BuildStatusResponse
from ..types.build_submit_response import BuildSubmitResponse
from .raw_client import AsyncRawBuildsClient, RawBuildsClient

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


class BuildsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawBuildsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawBuildsClient
        """
        return self._raw_client

    def prepare(
        self, *, agent_name: str, namespace: str, tag: str, request_options: typing.Optional[RequestOptions] = None
    ) -> BuildPrepareResponse:
        """
        Return a presigned URL for uploading a build context archive to GCS.

        Parameters
        ----------
        agent_name : str
            Agent short name (without namespace prefix)

        namespace : str
            Target namespace slug for the build

        tag : str
            Image tag to build/push (typically git hash)

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

        Returns
        -------
        BuildPrepareResponse
            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.builds.prepare(
            agent_name="my-agent",
            namespace="acme",
            tag="abc123def456",
        )
        """
        _response = self._raw_client.prepare(
            agent_name=agent_name, namespace=namespace, tag=tag, request_options=request_options
        )
        return _response.data

    def submit(
        self,
        *,
        agent_name: str,
        bucket: str,
        namespace: str,
        object_key: str,
        tag: str,
        git_branch: typing.Optional[str] = OMIT,
        git_hash: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> BuildSubmitResponse:
        """
        Submit a Cloud Build build for an uploaded build context archive.

        Parameters
        ----------
        agent_name : str
            Agent short name

        bucket : str
            GCS bucket containing uploaded build context archive.

        namespace : str
            Target namespace slug

        object_key : str
            GCS object key for the uploaded build context archive.

        tag : str
            Image tag to build/push

        git_branch : typing.Optional[str]
            Optional git branch name for metadata.

        git_hash : typing.Optional[str]
            Optional git hash for metadata.

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

        Returns
        -------
        BuildSubmitResponse
            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.builds.submit(
            agent_name="agent_name",
            bucket="bucket",
            namespace="namespace",
            object_key="object_key",
            tag="tag",
        )
        """
        _response = self._raw_client.submit(
            agent_name=agent_name,
            bucket=bucket,
            namespace=namespace,
            object_key=object_key,
            tag=tag,
            git_branch=git_branch,
            git_hash=git_hash,
            request_options=request_options,
        )
        return _response.data

    def retrieve(
        self, build_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> BuildStatusResponse:
        """
        Get build status for a Cloud Build build ID (proxied).

        Parameters
        ----------
        build_id : str

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

        Returns
        -------
        BuildStatusResponse
            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.builds.retrieve(
            build_id="build_id",
        )
        """
        _response = self._raw_client.retrieve(build_id, request_options=request_options)
        return _response.data


class AsyncBuildsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawBuildsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawBuildsClient
        """
        return self._raw_client

    async def prepare(
        self, *, agent_name: str, namespace: str, tag: str, request_options: typing.Optional[RequestOptions] = None
    ) -> BuildPrepareResponse:
        """
        Return a presigned URL for uploading a build context archive to GCS.

        Parameters
        ----------
        agent_name : str
            Agent short name (without namespace prefix)

        namespace : str
            Target namespace slug for the build

        tag : str
            Image tag to build/push (typically git hash)

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

        Returns
        -------
        BuildPrepareResponse
            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.builds.prepare(
                agent_name="my-agent",
                namespace="acme",
                tag="abc123def456",
            )


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

    async def submit(
        self,
        *,
        agent_name: str,
        bucket: str,
        namespace: str,
        object_key: str,
        tag: str,
        git_branch: typing.Optional[str] = OMIT,
        git_hash: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> BuildSubmitResponse:
        """
        Submit a Cloud Build build for an uploaded build context archive.

        Parameters
        ----------
        agent_name : str
            Agent short name

        bucket : str
            GCS bucket containing uploaded build context archive.

        namespace : str
            Target namespace slug

        object_key : str
            GCS object key for the uploaded build context archive.

        tag : str
            Image tag to build/push

        git_branch : typing.Optional[str]
            Optional git branch name for metadata.

        git_hash : typing.Optional[str]
            Optional git hash for metadata.

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

        Returns
        -------
        BuildSubmitResponse
            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.builds.submit(
                agent_name="agent_name",
                bucket="bucket",
                namespace="namespace",
                object_key="object_key",
                tag="tag",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.submit(
            agent_name=agent_name,
            bucket=bucket,
            namespace=namespace,
            object_key=object_key,
            tag=tag,
            git_branch=git_branch,
            git_hash=git_hash,
            request_options=request_options,
        )
        return _response.data

    async def retrieve(
        self, build_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> BuildStatusResponse:
        """
        Get build status for a Cloud Build build ID (proxied).

        Parameters
        ----------
        build_id : str

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

        Returns
        -------
        BuildStatusResponse
            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.builds.retrieve(
                build_id="build_id",
            )


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