# 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 .raw_client import AsyncRawCrmClient, RawCrmClient
from .types.list_crm_products_response import ListCrmProductsResponse
from .types.upsert_crm_deal_response import UpsertCrmDealResponse
from .types.upsert_crm_product_response import UpsertCrmProductResponse
from .types.upsert_deal_line_item_association_response import UpsertDealLineItemAssociationResponse
from .types.upsert_line_item_response import UpsertLineItemResponse

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


class CrmClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawCrmClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawCrmClient
        """
        return self._raw_client

    def upsert_deal_line_item_association(
        self,
        *,
        deal_external_id: str,
        line_item_external_id: str,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpsertDealLineItemAssociationResponse:
        """
        Parameters
        ----------
        deal_external_id : str

        line_item_external_id : str

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

        Returns
        -------
        UpsertDealLineItemAssociationResponse
            Created

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

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.crm.upsert_deal_line_item_association(
            deal_external_id="deal_external_id",
            line_item_external_id="line_item_external_id",
        )
        """
        _response = self._raw_client.upsert_deal_line_item_association(
            deal_external_id=deal_external_id,
            line_item_external_id=line_item_external_id,
            request_options=request_options,
        )
        return _response.data

    def upsert_line_item(
        self,
        *,
        amount: str,
        interval: str,
        line_item_external_id: str,
        product_external_id: str,
        quantity: int,
        discount_percentage: typing.Optional[str] = OMIT,
        term_month: typing.Optional[int] = OMIT,
        total_discount: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpsertLineItemResponse:
        """
        Parameters
        ----------
        amount : str

        interval : str

        line_item_external_id : str

        product_external_id : str

        quantity : int

        discount_percentage : typing.Optional[str]

        term_month : typing.Optional[int]

        total_discount : typing.Optional[str]

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

        Returns
        -------
        UpsertLineItemResponse
            Created

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

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.crm.upsert_line_item(
            amount="amount",
            interval="interval",
            line_item_external_id="line_item_external_id",
            product_external_id="product_external_id",
            quantity=1,
        )
        """
        _response = self._raw_client.upsert_line_item(
            amount=amount,
            interval=interval,
            line_item_external_id=line_item_external_id,
            product_external_id=product_external_id,
            quantity=quantity,
            discount_percentage=discount_percentage,
            term_month=term_month,
            total_discount=total_discount,
            request_options=request_options,
        )
        return _response.data

    def upsert_crm_deal(
        self,
        *,
        crm_company_key: str,
        crm_type: str,
        deal_external_id: str,
        arr: typing.Optional[str] = OMIT,
        crm_company_id: typing.Optional[str] = OMIT,
        crm_product_id: typing.Optional[str] = OMIT,
        deal_name: typing.Optional[str] = OMIT,
        deal_stage: typing.Optional[str] = OMIT,
        mrr: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpsertCrmDealResponse:
        """
        Parameters
        ----------
        crm_company_key : str

        crm_type : str

        deal_external_id : str

        arr : typing.Optional[str]

        crm_company_id : typing.Optional[str]

        crm_product_id : typing.Optional[str]

        deal_name : typing.Optional[str]

        deal_stage : typing.Optional[str]

        mrr : typing.Optional[str]

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

        Returns
        -------
        UpsertCrmDealResponse
            Created

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

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.crm.upsert_crm_deal(
            crm_company_key="crm_company_key",
            crm_type="crm_type",
            deal_external_id="deal_external_id",
        )
        """
        _response = self._raw_client.upsert_crm_deal(
            crm_company_key=crm_company_key,
            crm_type=crm_type,
            deal_external_id=deal_external_id,
            arr=arr,
            crm_company_id=crm_company_id,
            crm_product_id=crm_product_id,
            deal_name=deal_name,
            deal_stage=deal_stage,
            mrr=mrr,
            request_options=request_options,
        )
        return _response.data

    def list_crm_products(
        self,
        *,
        ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        name: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListCrmProductsResponse:
        """
        Parameters
        ----------
        ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]

        name : 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
        -------
        ListCrmProductsResponse
            OK

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

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.crm.list_crm_products()
        """
        _response = self._raw_client.list_crm_products(
            ids=ids, name=name, limit=limit, offset=offset, request_options=request_options
        )
        return _response.data

    def upsert_crm_product(
        self,
        *,
        currency: str,
        description: str,
        external_id: str,
        interval: str,
        name: str,
        price: str,
        quantity: int,
        sku: str,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpsertCrmProductResponse:
        """
        Parameters
        ----------
        currency : str

        description : str

        external_id : str

        interval : str

        name : str

        price : str

        quantity : int

        sku : str

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

        Returns
        -------
        UpsertCrmProductResponse
            Created

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

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.crm.upsert_crm_product(
            currency="currency",
            description="description",
            external_id="external_id",
            interval="interval",
            name="name",
            price="price",
            quantity=1,
            sku="sku",
        )
        """
        _response = self._raw_client.upsert_crm_product(
            currency=currency,
            description=description,
            external_id=external_id,
            interval=interval,
            name=name,
            price=price,
            quantity=quantity,
            sku=sku,
            request_options=request_options,
        )
        return _response.data


class AsyncCrmClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawCrmClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawCrmClient
        """
        return self._raw_client

    async def upsert_deal_line_item_association(
        self,
        *,
        deal_external_id: str,
        line_item_external_id: str,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpsertDealLineItemAssociationResponse:
        """
        Parameters
        ----------
        deal_external_id : str

        line_item_external_id : str

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

        Returns
        -------
        UpsertDealLineItemAssociationResponse
            Created

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.crm.upsert_deal_line_item_association(
                deal_external_id="deal_external_id",
                line_item_external_id="line_item_external_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.upsert_deal_line_item_association(
            deal_external_id=deal_external_id,
            line_item_external_id=line_item_external_id,
            request_options=request_options,
        )
        return _response.data

    async def upsert_line_item(
        self,
        *,
        amount: str,
        interval: str,
        line_item_external_id: str,
        product_external_id: str,
        quantity: int,
        discount_percentage: typing.Optional[str] = OMIT,
        term_month: typing.Optional[int] = OMIT,
        total_discount: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpsertLineItemResponse:
        """
        Parameters
        ----------
        amount : str

        interval : str

        line_item_external_id : str

        product_external_id : str

        quantity : int

        discount_percentage : typing.Optional[str]

        term_month : typing.Optional[int]

        total_discount : typing.Optional[str]

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

        Returns
        -------
        UpsertLineItemResponse
            Created

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.crm.upsert_line_item(
                amount="amount",
                interval="interval",
                line_item_external_id="line_item_external_id",
                product_external_id="product_external_id",
                quantity=1,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.upsert_line_item(
            amount=amount,
            interval=interval,
            line_item_external_id=line_item_external_id,
            product_external_id=product_external_id,
            quantity=quantity,
            discount_percentage=discount_percentage,
            term_month=term_month,
            total_discount=total_discount,
            request_options=request_options,
        )
        return _response.data

    async def upsert_crm_deal(
        self,
        *,
        crm_company_key: str,
        crm_type: str,
        deal_external_id: str,
        arr: typing.Optional[str] = OMIT,
        crm_company_id: typing.Optional[str] = OMIT,
        crm_product_id: typing.Optional[str] = OMIT,
        deal_name: typing.Optional[str] = OMIT,
        deal_stage: typing.Optional[str] = OMIT,
        mrr: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpsertCrmDealResponse:
        """
        Parameters
        ----------
        crm_company_key : str

        crm_type : str

        deal_external_id : str

        arr : typing.Optional[str]

        crm_company_id : typing.Optional[str]

        crm_product_id : typing.Optional[str]

        deal_name : typing.Optional[str]

        deal_stage : typing.Optional[str]

        mrr : typing.Optional[str]

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

        Returns
        -------
        UpsertCrmDealResponse
            Created

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.crm.upsert_crm_deal(
                crm_company_key="crm_company_key",
                crm_type="crm_type",
                deal_external_id="deal_external_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.upsert_crm_deal(
            crm_company_key=crm_company_key,
            crm_type=crm_type,
            deal_external_id=deal_external_id,
            arr=arr,
            crm_company_id=crm_company_id,
            crm_product_id=crm_product_id,
            deal_name=deal_name,
            deal_stage=deal_stage,
            mrr=mrr,
            request_options=request_options,
        )
        return _response.data

    async def list_crm_products(
        self,
        *,
        ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        name: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListCrmProductsResponse:
        """
        Parameters
        ----------
        ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]

        name : 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
        -------
        ListCrmProductsResponse
            OK

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.crm.list_crm_products()


        asyncio.run(main())
        """
        _response = await self._raw_client.list_crm_products(
            ids=ids, name=name, limit=limit, offset=offset, request_options=request_options
        )
        return _response.data

    async def upsert_crm_product(
        self,
        *,
        currency: str,
        description: str,
        external_id: str,
        interval: str,
        name: str,
        price: str,
        quantity: int,
        sku: str,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpsertCrmProductResponse:
        """
        Parameters
        ----------
        currency : str

        description : str

        external_id : str

        interval : str

        name : str

        price : str

        quantity : int

        sku : str

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

        Returns
        -------
        UpsertCrmProductResponse
            Created

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.crm.upsert_crm_product(
                currency="currency",
                description="description",
                external_id="external_id",
                interval="interval",
                name="name",
                price="price",
                quantity=1,
                sku="sku",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.upsert_crm_product(
            currency=currency,
            description=description,
            external_id=external_id,
            interval=interval,
            name=name,
            price=price,
            quantity=quantity,
            sku=sku,
            request_options=request_options,
        )
        return _response.data
