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

import typing

from ..commons.types.entity_id_base import EntityIdBase
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from .raw_client import AsyncRawCustomersClient, RawCustomersClient
from .types.customer_field import CustomerField
from .types.customer_filter import CustomerFilter
from .types.customer_response import CustomerResponse
from .types.customer_status import CustomerStatus
from .types.customers_search_response import CustomersSearchResponse

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


class CustomersClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawCustomersClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawCustomersClient
        """
        return self._raw_client

    def search(
        self,
        *,
        sort: typing.Optional[CustomerField] = OMIT,
        filter: typing.Optional[CustomerFilter] = OMIT,
        page: typing.Optional[int] = OMIT,
        size: typing.Optional[int] = OMIT,
        sort_desc: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CustomersSearchResponse:
        """
        Parameters
        ----------
        sort : typing.Optional[CustomerField]
            The field to sort by, defaults to created timestamp

        filter : typing.Optional[CustomerFilter]
            The filter to apply to the customers.

        page : typing.Optional[int]
            Page number to return, defaults to 0

        size : typing.Optional[int]
            The size of the page to return, defaults to 20

        sort_desc : typing.Optional[bool]
            Whether to sort descending, defaults to true

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

        Returns
        -------
        CustomersSearchResponse

        Examples
        --------
        from mavenagi import MavenAGI

        client = MavenAGI(
            organization_id="YOUR_ORGANIZATION_ID",
            agent_id="YOUR_AGENT_ID",
            app_id="YOUR_APP_ID",
            app_secret="YOUR_APP_SECRET",
        )
        client.customers.search()
        """
        _response = self._raw_client.search(
            sort=sort, filter=filter, page=page, size=size, sort_desc=sort_desc, request_options=request_options
        )
        return _response.data

    def create_or_update(
        self, *, customer_id: EntityIdBase, name: str, request_options: typing.Optional[RequestOptions] = None
    ) -> CustomerResponse:
        """
        Update a customer of an agent or create it if it doesn't exist. In case of an update, fields not provided (e.g., description, status) will be preserved.

        Parameters
        ----------
        customer_id : EntityIdBase
            ID that uniquely identifies this customer

        name : str

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

        Returns
        -------
        CustomerResponse

        Examples
        --------
        from mavenagi import MavenAGI
        from mavenagi.commons import EntityIdBase

        client = MavenAGI(
            organization_id="YOUR_ORGANIZATION_ID",
            agent_id="YOUR_AGENT_ID",
            app_id="YOUR_APP_ID",
            app_secret="YOUR_APP_SECRET",
        )
        client.customers.create_or_update(
            customer_id=EntityIdBase(
                reference_id="acme",
            ),
            name="Acme Corporation",
        )
        """
        _response = self._raw_client.create_or_update(
            customer_id=customer_id, name=name, request_options=request_options
        )
        return _response.data

    def get(
        self,
        customer_reference_id: str,
        *,
        app_id: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CustomerResponse:
        """
        Get a customer by its supplied ID

        Parameters
        ----------
        customer_reference_id : str
            The reference ID of the customer to get. All other entity ID fields are inferred from the request.

        app_id : typing.Optional[str]
            The App ID of the customer to get. If not provided, the ID of the calling app will be used.

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

        Returns
        -------
        CustomerResponse

        Examples
        --------
        from mavenagi import MavenAGI

        client = MavenAGI(
            organization_id="YOUR_ORGANIZATION_ID",
            agent_id="YOUR_AGENT_ID",
            app_id="YOUR_APP_ID",
            app_secret="YOUR_APP_SECRET",
        )
        client.customers.get(
            customer_reference_id="acme",
        )
        """
        _response = self._raw_client.get(customer_reference_id, app_id=app_id, request_options=request_options)
        return _response.data

    def patch(
        self,
        customer_reference_id: str,
        *,
        app_id: typing.Optional[str] = OMIT,
        name: typing.Optional[str] = OMIT,
        description: typing.Optional[str] = OMIT,
        status: typing.Optional[CustomerStatus] = OMIT,
        metadata: typing.Optional[typing.Dict[str, str]] = OMIT,
        assignees: typing.Optional[typing.Set[str]] = OMIT,
        members: typing.Optional[typing.Set[str]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CustomerResponse:
        """
        Update mutable customer fields

        The `appId` field can be provided to update a customer owned by a different app.
        All other fields will overwrite the existing value on the customer only if provided.

        Parameters
        ----------
        customer_reference_id : str
            The reference ID of the customer to update. All other entity ID fields are inferred from the request.

        app_id : typing.Optional[str]
            The App ID of the customer to update. If not provided, the ID of the calling app will be used.

        name : typing.Optional[str]
            The name of the customer.

        description : typing.Optional[str]
            The description of the customer.

        status : typing.Optional[CustomerStatus]
            Whether or not the customer is in active use.

            Only active customers will be available for agent interactions.

        metadata : typing.Optional[typing.Dict[str, str]]
            Metadata associated with the customer. If not provided, the existing metadata will be preserved.

        assignees : typing.Optional[typing.Set[str]]
            Set of agent user IDs to assign to this customer. If provided, replaces all existing assignees.

        members : typing.Optional[typing.Set[str]]
            Set of agent user IDs who are members of this customer. If provided, replaces all existing members.

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

        Returns
        -------
        CustomerResponse
            The updated customer

        Examples
        --------
        from mavenagi import MavenAGI

        client = MavenAGI(
            organization_id="YOUR_ORGANIZATION_ID",
            agent_id="YOUR_AGENT_ID",
            app_id="YOUR_APP_ID",
            app_secret="YOUR_APP_SECRET",
        )
        client.customers.patch(
            customer_reference_id="customerReferenceId",
        )
        """
        _response = self._raw_client.patch(
            customer_reference_id,
            app_id=app_id,
            name=name,
            description=description,
            status=status,
            metadata=metadata,
            assignees=assignees,
            members=members,
            request_options=request_options,
        )
        return _response.data


class AsyncCustomersClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawCustomersClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawCustomersClient
        """
        return self._raw_client

    async def search(
        self,
        *,
        sort: typing.Optional[CustomerField] = OMIT,
        filter: typing.Optional[CustomerFilter] = OMIT,
        page: typing.Optional[int] = OMIT,
        size: typing.Optional[int] = OMIT,
        sort_desc: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CustomersSearchResponse:
        """
        Parameters
        ----------
        sort : typing.Optional[CustomerField]
            The field to sort by, defaults to created timestamp

        filter : typing.Optional[CustomerFilter]
            The filter to apply to the customers.

        page : typing.Optional[int]
            Page number to return, defaults to 0

        size : typing.Optional[int]
            The size of the page to return, defaults to 20

        sort_desc : typing.Optional[bool]
            Whether to sort descending, defaults to true

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

        Returns
        -------
        CustomersSearchResponse

        Examples
        --------
        import asyncio

        from mavenagi import AsyncMavenAGI

        client = AsyncMavenAGI(
            organization_id="YOUR_ORGANIZATION_ID",
            agent_id="YOUR_AGENT_ID",
            app_id="YOUR_APP_ID",
            app_secret="YOUR_APP_SECRET",
        )


        async def main() -> None:
            await client.customers.search()


        asyncio.run(main())
        """
        _response = await self._raw_client.search(
            sort=sort, filter=filter, page=page, size=size, sort_desc=sort_desc, request_options=request_options
        )
        return _response.data

    async def create_or_update(
        self, *, customer_id: EntityIdBase, name: str, request_options: typing.Optional[RequestOptions] = None
    ) -> CustomerResponse:
        """
        Update a customer of an agent or create it if it doesn't exist. In case of an update, fields not provided (e.g., description, status) will be preserved.

        Parameters
        ----------
        customer_id : EntityIdBase
            ID that uniquely identifies this customer

        name : str

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

        Returns
        -------
        CustomerResponse

        Examples
        --------
        import asyncio

        from mavenagi import AsyncMavenAGI
        from mavenagi.commons import EntityIdBase

        client = AsyncMavenAGI(
            organization_id="YOUR_ORGANIZATION_ID",
            agent_id="YOUR_AGENT_ID",
            app_id="YOUR_APP_ID",
            app_secret="YOUR_APP_SECRET",
        )


        async def main() -> None:
            await client.customers.create_or_update(
                customer_id=EntityIdBase(
                    reference_id="acme",
                ),
                name="Acme Corporation",
            )


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

    async def get(
        self,
        customer_reference_id: str,
        *,
        app_id: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CustomerResponse:
        """
        Get a customer by its supplied ID

        Parameters
        ----------
        customer_reference_id : str
            The reference ID of the customer to get. All other entity ID fields are inferred from the request.

        app_id : typing.Optional[str]
            The App ID of the customer to get. If not provided, the ID of the calling app will be used.

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

        Returns
        -------
        CustomerResponse

        Examples
        --------
        import asyncio

        from mavenagi import AsyncMavenAGI

        client = AsyncMavenAGI(
            organization_id="YOUR_ORGANIZATION_ID",
            agent_id="YOUR_AGENT_ID",
            app_id="YOUR_APP_ID",
            app_secret="YOUR_APP_SECRET",
        )


        async def main() -> None:
            await client.customers.get(
                customer_reference_id="acme",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get(customer_reference_id, app_id=app_id, request_options=request_options)
        return _response.data

    async def patch(
        self,
        customer_reference_id: str,
        *,
        app_id: typing.Optional[str] = OMIT,
        name: typing.Optional[str] = OMIT,
        description: typing.Optional[str] = OMIT,
        status: typing.Optional[CustomerStatus] = OMIT,
        metadata: typing.Optional[typing.Dict[str, str]] = OMIT,
        assignees: typing.Optional[typing.Set[str]] = OMIT,
        members: typing.Optional[typing.Set[str]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CustomerResponse:
        """
        Update mutable customer fields

        The `appId` field can be provided to update a customer owned by a different app.
        All other fields will overwrite the existing value on the customer only if provided.

        Parameters
        ----------
        customer_reference_id : str
            The reference ID of the customer to update. All other entity ID fields are inferred from the request.

        app_id : typing.Optional[str]
            The App ID of the customer to update. If not provided, the ID of the calling app will be used.

        name : typing.Optional[str]
            The name of the customer.

        description : typing.Optional[str]
            The description of the customer.

        status : typing.Optional[CustomerStatus]
            Whether or not the customer is in active use.

            Only active customers will be available for agent interactions.

        metadata : typing.Optional[typing.Dict[str, str]]
            Metadata associated with the customer. If not provided, the existing metadata will be preserved.

        assignees : typing.Optional[typing.Set[str]]
            Set of agent user IDs to assign to this customer. If provided, replaces all existing assignees.

        members : typing.Optional[typing.Set[str]]
            Set of agent user IDs who are members of this customer. If provided, replaces all existing members.

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

        Returns
        -------
        CustomerResponse
            The updated customer

        Examples
        --------
        import asyncio

        from mavenagi import AsyncMavenAGI

        client = AsyncMavenAGI(
            organization_id="YOUR_ORGANIZATION_ID",
            agent_id="YOUR_AGENT_ID",
            app_id="YOUR_APP_ID",
            app_secret="YOUR_APP_SECRET",
        )


        async def main() -> None:
            await client.customers.patch(
                customer_reference_id="customerReferenceId",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.patch(
            customer_reference_id,
            app_id=app_id,
            name=name,
            description=description,
            status=status,
            metadata=metadata,
            assignees=assignees,
            members=members,
            request_options=request_options,
        )
        return _response.data
