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

import datetime as dt
import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from ..types.create_event_request_body import CreateEventRequestBody
from ..types.create_event_request_body_event_type import CreateEventRequestBodyEventType
from ..types.event_body import EventBody
from .raw_client import AsyncRawEventsClient, RawEventsClient
from .types.create_event_batch_response import CreateEventBatchResponse
from .types.create_event_response import CreateEventResponse
from .types.get_event_response import GetEventResponse
from .types.get_event_summaries_response import GetEventSummariesResponse
from .types.get_segment_integration_status_response import GetSegmentIntegrationStatusResponse
from .types.list_events_request_event_types_item import ListEventsRequestEventTypesItem
from .types.list_events_response import ListEventsResponse

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


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 create_event_batch(
        self,
        *,
        events: typing.Sequence[CreateEventRequestBody],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateEventBatchResponse:
        """
        Parameters
        ----------
        events : typing.Sequence[CreateEventRequestBody]

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

        Returns
        -------
        CreateEventBatchResponse
            Created

        Examples
        --------
        from schematic import CreateEventRequestBody, Schematic

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.events.create_event_batch(
            events=[
                CreateEventRequestBody(
                    event_type="identify",
                )
            ],
        )
        """
        _response = self._raw_client.create_event_batch(events=events, request_options=request_options)
        return _response.data

    def get_event_summaries(
        self,
        *,
        q: typing.Optional[str] = None,
        event_subtypes: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> GetEventSummariesResponse:
        """
        Parameters
        ----------
        q : typing.Optional[str]

        event_subtypes : typing.Optional[typing.Union[str, typing.Sequence[str]]]

        limit : typing.Optional[int]
            Page limit (default 100)

        offset : typing.Optional[int]
            Page offset (default 0)

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

        Returns
        -------
        GetEventSummariesResponse
            OK

        Examples
        --------
        from schematic import Schematic

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.events.get_event_summaries()
        """
        _response = self._raw_client.get_event_summaries(
            q=q, event_subtypes=event_subtypes, limit=limit, offset=offset, request_options=request_options
        )
        return _response.data

    def list_events(
        self,
        *,
        company_id: typing.Optional[str] = None,
        event_subtype: typing.Optional[str] = None,
        event_types: typing.Optional[
            typing.Union[ListEventsRequestEventTypesItem, typing.Sequence[ListEventsRequestEventTypesItem]]
        ] = None,
        flag_id: typing.Optional[str] = None,
        user_id: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListEventsResponse:
        """
        Parameters
        ----------
        company_id : typing.Optional[str]

        event_subtype : typing.Optional[str]

        event_types : typing.Optional[typing.Union[ListEventsRequestEventTypesItem, typing.Sequence[ListEventsRequestEventTypesItem]]]

        flag_id : typing.Optional[str]

        user_id : typing.Optional[str]

        limit : typing.Optional[int]
            Page limit (default 100)

        offset : typing.Optional[int]
            Page offset (default 0)

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

        Returns
        -------
        ListEventsResponse
            OK

        Examples
        --------
        from schematic import Schematic

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.events.list_events()
        """
        _response = self._raw_client.list_events(
            company_id=company_id,
            event_subtype=event_subtype,
            event_types=event_types,
            flag_id=flag_id,
            user_id=user_id,
            limit=limit,
            offset=offset,
            request_options=request_options,
        )
        return _response.data

    def create_event(
        self,
        *,
        event_type: CreateEventRequestBodyEventType,
        body: typing.Optional[EventBody] = OMIT,
        sent_at: typing.Optional[dt.datetime] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateEventResponse:
        """
        Parameters
        ----------
        event_type : CreateEventRequestBodyEventType
            Either 'identify' or 'track'

        body : typing.Optional[EventBody]

        sent_at : typing.Optional[dt.datetime]
            Optionally provide a timestamp at which the event was sent to Schematic

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

        Returns
        -------
        CreateEventResponse
            Created

        Examples
        --------
        from schematic import Schematic

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.events.create_event(
            event_type="identify",
        )
        """
        _response = self._raw_client.create_event(
            event_type=event_type, body=body, sent_at=sent_at, request_options=request_options
        )
        return _response.data

    def get_event(self, event_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> GetEventResponse:
        """
        Parameters
        ----------
        event_id : str
            event_id

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

        Returns
        -------
        GetEventResponse
            OK

        Examples
        --------
        from schematic import Schematic

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.events.get_event(
            event_id="event_id",
        )
        """
        _response = self._raw_client.get_event(event_id, request_options=request_options)
        return _response.data

    def get_segment_integration_status(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> GetSegmentIntegrationStatusResponse:
        """
        Parameters
        ----------
        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        GetSegmentIntegrationStatusResponse
            OK

        Examples
        --------
        from schematic import Schematic

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.events.get_segment_integration_status()
        """
        _response = self._raw_client.get_segment_integration_status(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 create_event_batch(
        self,
        *,
        events: typing.Sequence[CreateEventRequestBody],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateEventBatchResponse:
        """
        Parameters
        ----------
        events : typing.Sequence[CreateEventRequestBody]

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

        Returns
        -------
        CreateEventBatchResponse
            Created

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic, CreateEventRequestBody

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.events.create_event_batch(
                events=[
                    CreateEventRequestBody(
                        event_type="identify",
                    )
                ],
            )


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

    async def get_event_summaries(
        self,
        *,
        q: typing.Optional[str] = None,
        event_subtypes: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> GetEventSummariesResponse:
        """
        Parameters
        ----------
        q : typing.Optional[str]

        event_subtypes : typing.Optional[typing.Union[str, typing.Sequence[str]]]

        limit : typing.Optional[int]
            Page limit (default 100)

        offset : typing.Optional[int]
            Page offset (default 0)

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

        Returns
        -------
        GetEventSummariesResponse
            OK

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.events.get_event_summaries()


        asyncio.run(main())
        """
        _response = await self._raw_client.get_event_summaries(
            q=q, event_subtypes=event_subtypes, limit=limit, offset=offset, request_options=request_options
        )
        return _response.data

    async def list_events(
        self,
        *,
        company_id: typing.Optional[str] = None,
        event_subtype: typing.Optional[str] = None,
        event_types: typing.Optional[
            typing.Union[ListEventsRequestEventTypesItem, typing.Sequence[ListEventsRequestEventTypesItem]]
        ] = None,
        flag_id: typing.Optional[str] = None,
        user_id: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListEventsResponse:
        """
        Parameters
        ----------
        company_id : typing.Optional[str]

        event_subtype : typing.Optional[str]

        event_types : typing.Optional[typing.Union[ListEventsRequestEventTypesItem, typing.Sequence[ListEventsRequestEventTypesItem]]]

        flag_id : typing.Optional[str]

        user_id : typing.Optional[str]

        limit : typing.Optional[int]
            Page limit (default 100)

        offset : typing.Optional[int]
            Page offset (default 0)

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

        Returns
        -------
        ListEventsResponse
            OK

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.events.list_events()


        asyncio.run(main())
        """
        _response = await self._raw_client.list_events(
            company_id=company_id,
            event_subtype=event_subtype,
            event_types=event_types,
            flag_id=flag_id,
            user_id=user_id,
            limit=limit,
            offset=offset,
            request_options=request_options,
        )
        return _response.data

    async def create_event(
        self,
        *,
        event_type: CreateEventRequestBodyEventType,
        body: typing.Optional[EventBody] = OMIT,
        sent_at: typing.Optional[dt.datetime] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateEventResponse:
        """
        Parameters
        ----------
        event_type : CreateEventRequestBodyEventType
            Either 'identify' or 'track'

        body : typing.Optional[EventBody]

        sent_at : typing.Optional[dt.datetime]
            Optionally provide a timestamp at which the event was sent to Schematic

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

        Returns
        -------
        CreateEventResponse
            Created

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.events.create_event(
                event_type="identify",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_event(
            event_type=event_type, body=body, sent_at=sent_at, request_options=request_options
        )
        return _response.data

    async def get_event(
        self, event_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> GetEventResponse:
        """
        Parameters
        ----------
        event_id : str
            event_id

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

        Returns
        -------
        GetEventResponse
            OK

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.events.get_event(
                event_id="event_id",
            )


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

    async def get_segment_integration_status(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> GetSegmentIntegrationStatusResponse:
        """
        Parameters
        ----------
        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        GetSegmentIntegrationStatusResponse
            OK

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.events.get_segment_integration_status()


        asyncio.run(main())
        """
        _response = await self._raw_client.get_segment_integration_status(request_options=request_options)
        return _response.data
