# 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.version_event_list_response import VersionEventListResponse
from ...types.version_event_type import VersionEventType
from .raw_client import AsyncRawEventsClient, RawEventsClient


class EventsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawEventsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawEventsClient
        """
        return self._raw_client

    def list(
        self,
        branch_id: str,
        *,
        event_type: typing.Optional[VersionEventType] = None,
        after_sequence_id: typing.Optional[int] = None,
        before_sequence_id: typing.Optional[int] = None,
        limit: typing.Optional[int] = None,
        descending: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> VersionEventListResponse:
        """
        List lifecycle events across all versions for a branch.

        Parameters
        ----------
        branch_id : str

        event_type : typing.Optional[VersionEventType]
            Filter by event type

        after_sequence_id : typing.Optional[int]
            Return events after this sequence_id (for ascending pagination)

        before_sequence_id : typing.Optional[int]
            Return events before this sequence_id (for descending pagination)

        limit : typing.Optional[int]
            Maximum events to return

        descending : typing.Optional[bool]
            Order by sequence_id descending (newest first)

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

        Returns
        -------
        VersionEventListResponse
            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.branches.events.list(
            branch_id="branch_id",
        )
        """
        _response = self._raw_client.list(
            branch_id,
            event_type=event_type,
            after_sequence_id=after_sequence_id,
            before_sequence_id=before_sequence_id,
            limit=limit,
            descending=descending,
            request_options=request_options,
        )
        return _response.data


class AsyncEventsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawEventsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawEventsClient
        """
        return self._raw_client

    async def list(
        self,
        branch_id: str,
        *,
        event_type: typing.Optional[VersionEventType] = None,
        after_sequence_id: typing.Optional[int] = None,
        before_sequence_id: typing.Optional[int] = None,
        limit: typing.Optional[int] = None,
        descending: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> VersionEventListResponse:
        """
        List lifecycle events across all versions for a branch.

        Parameters
        ----------
        branch_id : str

        event_type : typing.Optional[VersionEventType]
            Filter by event type

        after_sequence_id : typing.Optional[int]
            Return events after this sequence_id (for ascending pagination)

        before_sequence_id : typing.Optional[int]
            Return events before this sequence_id (for descending pagination)

        limit : typing.Optional[int]
            Maximum events to return

        descending : typing.Optional[bool]
            Order by sequence_id descending (newest first)

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

        Returns
        -------
        VersionEventListResponse
            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.branches.events.list(
                branch_id="branch_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.list(
            branch_id,
            event_type=event_type,
            after_sequence_id=after_sequence_id,
            before_sequence_id=before_sequence_id,
            limit=limit,
            descending=descending,
            request_options=request_options,
        )
        return _response.data
