# 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.extraction_field import ExtractionField
from .raw_client import AsyncRawExtractionSchemasClient, RawExtractionSchemasClient
from .types.extraction_schemas_create_response import ExtractionSchemasCreateResponse
from .types.extraction_schemas_delete_response import ExtractionSchemasDeleteResponse
from .types.extraction_schemas_get_response import ExtractionSchemasGetResponse
from .types.extraction_schemas_list_response import ExtractionSchemasListResponse
from .types.extraction_schemas_update_response import ExtractionSchemasUpdateResponse

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


class ExtractionSchemasClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawExtractionSchemasClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawExtractionSchemasClient
        """
        return self._raw_client

    def list(
        self, *, project: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> ExtractionSchemasListResponse:
        """
        Returns all extraction schemas in a project.

        Parameters
        ----------
        project : typing.Optional[str]
            The name of the project to list extraction schemas for.

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

        Returns
        -------
        ExtractionSchemasListResponse
            Success response

        Examples
        --------
        from phonic import Phonic

        client = Phonic(
            token="YOUR_TOKEN",
        )
        client.extraction_schemas.list()
        """
        _response = self._raw_client.list(project=project, request_options=request_options)
        return _response.data

    def create(
        self,
        *,
        name: str,
        prompt: str,
        fields: typing.Sequence[ExtractionField],
        project: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ExtractionSchemasCreateResponse:
        """
        Creates a new extraction schema in a project.

        Parameters
        ----------
        name : str
            A name for the extraction schema.

        prompt : str
            Instructions for how to extract data from conversations.

        fields : typing.Sequence[ExtractionField]
            Array of field definitions.

        project : typing.Optional[str]
            The name of the project to create the extraction schema in.

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

        Returns
        -------
        ExtractionSchemasCreateResponse
            Success response

        Examples
        --------
        from phonic import ExtractionField, Phonic

        client = Phonic(
            token="YOUR_TOKEN",
        )
        client.extraction_schemas.create(
            name="Appointment details",
            prompt="Dates should be in `9 Apr 2025` format. Prices should be in $150.00 format.",
            fields=[
                ExtractionField(
                    name="Date",
                    type="string",
                    description="The date of the appointment",
                ),
                ExtractionField(
                    name="Copay",
                    type="string",
                    description="Amount of money the patient pays for the appointment",
                ),
                ExtractionField(
                    name="Confirmed as booked",
                    type="bool",
                    description="Is the appointment confirmed as booked?",
                ),
            ],
        )
        """
        _response = self._raw_client.create(
            name=name, prompt=prompt, fields=fields, project=project, request_options=request_options
        )
        return _response.data

    def get(
        self,
        name_or_id: str,
        *,
        project: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ExtractionSchemasGetResponse:
        """
        Returns an extraction schema by name or ID.

        Parameters
        ----------
        name_or_id : str
            The name or the ID of the extraction schema to get.

        project : typing.Optional[str]
            The name of the project containing the extraction schema. Only used when `nameOrId` is a name.

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

        Returns
        -------
        ExtractionSchemasGetResponse
            Success response

        Examples
        --------
        from phonic import Phonic

        client = Phonic(
            token="YOUR_TOKEN",
        )
        client.extraction_schemas.get(
            name_or_id="nameOrId",
        )
        """
        _response = self._raw_client.get(name_or_id, project=project, request_options=request_options)
        return _response.data

    def delete(
        self,
        name_or_id: str,
        *,
        project: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ExtractionSchemasDeleteResponse:
        """
        Deletes an extraction schema by name or ID.

        Parameters
        ----------
        name_or_id : str
            The name or the ID of the extraction schema to delete.

        project : typing.Optional[str]
            The name of the project containing the extraction schema. Only used when `nameOrId` is a name.

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

        Returns
        -------
        ExtractionSchemasDeleteResponse
            Success response

        Examples
        --------
        from phonic import Phonic

        client = Phonic(
            token="YOUR_TOKEN",
        )
        client.extraction_schemas.delete(
            name_or_id="nameOrId",
        )
        """
        _response = self._raw_client.delete(name_or_id, project=project, request_options=request_options)
        return _response.data

    def update(
        self,
        name_or_id: str,
        *,
        project: typing.Optional[str] = None,
        name: typing.Optional[str] = OMIT,
        prompt: typing.Optional[str] = OMIT,
        fields: typing.Optional[typing.Sequence[ExtractionField]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ExtractionSchemasUpdateResponse:
        """
        Updates an extraction schema by name or ID.

        Parameters
        ----------
        name_or_id : str
            The name or the ID of the extraction schema to update.

        project : typing.Optional[str]
            The name of the project containing the extraction schema. Only used when `nameOrId` is a name.

        name : typing.Optional[str]
            A name for the extraction schema.

        prompt : typing.Optional[str]
            Instructions for how to extract data from conversations.

        fields : typing.Optional[typing.Sequence[ExtractionField]]
            Array of field definitions.

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

        Returns
        -------
        ExtractionSchemasUpdateResponse
            Success response

        Examples
        --------
        from phonic import ExtractionField, Phonic

        client = Phonic(
            token="YOUR_TOKEN",
        )
        client.extraction_schemas.update(
            name_or_id="nameOrId",
            name="Updated appointment details",
            prompt="Updated extraction instructions. Dates should be in `9 Apr 2025` format.",
            fields=[
                ExtractionField(
                    name="Date",
                    type="string",
                    description="The date of the appointment",
                ),
                ExtractionField(
                    name="Time",
                    type="string",
                    description="The time of the appointment",
                ),
            ],
        )
        """
        _response = self._raw_client.update(
            name_or_id, project=project, name=name, prompt=prompt, fields=fields, request_options=request_options
        )
        return _response.data


class AsyncExtractionSchemasClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawExtractionSchemasClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawExtractionSchemasClient
        """
        return self._raw_client

    async def list(
        self, *, project: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> ExtractionSchemasListResponse:
        """
        Returns all extraction schemas in a project.

        Parameters
        ----------
        project : typing.Optional[str]
            The name of the project to list extraction schemas for.

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

        Returns
        -------
        ExtractionSchemasListResponse
            Success response

        Examples
        --------
        import asyncio

        from phonic import AsyncPhonic

        client = AsyncPhonic(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.extraction_schemas.list()


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

    async def create(
        self,
        *,
        name: str,
        prompt: str,
        fields: typing.Sequence[ExtractionField],
        project: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ExtractionSchemasCreateResponse:
        """
        Creates a new extraction schema in a project.

        Parameters
        ----------
        name : str
            A name for the extraction schema.

        prompt : str
            Instructions for how to extract data from conversations.

        fields : typing.Sequence[ExtractionField]
            Array of field definitions.

        project : typing.Optional[str]
            The name of the project to create the extraction schema in.

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

        Returns
        -------
        ExtractionSchemasCreateResponse
            Success response

        Examples
        --------
        import asyncio

        from phonic import AsyncPhonic, ExtractionField

        client = AsyncPhonic(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.extraction_schemas.create(
                name="Appointment details",
                prompt="Dates should be in `9 Apr 2025` format. Prices should be in $150.00 format.",
                fields=[
                    ExtractionField(
                        name="Date",
                        type="string",
                        description="The date of the appointment",
                    ),
                    ExtractionField(
                        name="Copay",
                        type="string",
                        description="Amount of money the patient pays for the appointment",
                    ),
                    ExtractionField(
                        name="Confirmed as booked",
                        type="bool",
                        description="Is the appointment confirmed as booked?",
                    ),
                ],
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create(
            name=name, prompt=prompt, fields=fields, project=project, request_options=request_options
        )
        return _response.data

    async def get(
        self,
        name_or_id: str,
        *,
        project: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ExtractionSchemasGetResponse:
        """
        Returns an extraction schema by name or ID.

        Parameters
        ----------
        name_or_id : str
            The name or the ID of the extraction schema to get.

        project : typing.Optional[str]
            The name of the project containing the extraction schema. Only used when `nameOrId` is a name.

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

        Returns
        -------
        ExtractionSchemasGetResponse
            Success response

        Examples
        --------
        import asyncio

        from phonic import AsyncPhonic

        client = AsyncPhonic(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.extraction_schemas.get(
                name_or_id="nameOrId",
            )


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

    async def delete(
        self,
        name_or_id: str,
        *,
        project: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ExtractionSchemasDeleteResponse:
        """
        Deletes an extraction schema by name or ID.

        Parameters
        ----------
        name_or_id : str
            The name or the ID of the extraction schema to delete.

        project : typing.Optional[str]
            The name of the project containing the extraction schema. Only used when `nameOrId` is a name.

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

        Returns
        -------
        ExtractionSchemasDeleteResponse
            Success response

        Examples
        --------
        import asyncio

        from phonic import AsyncPhonic

        client = AsyncPhonic(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.extraction_schemas.delete(
                name_or_id="nameOrId",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.delete(name_or_id, project=project, request_options=request_options)
        return _response.data

    async def update(
        self,
        name_or_id: str,
        *,
        project: typing.Optional[str] = None,
        name: typing.Optional[str] = OMIT,
        prompt: typing.Optional[str] = OMIT,
        fields: typing.Optional[typing.Sequence[ExtractionField]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ExtractionSchemasUpdateResponse:
        """
        Updates an extraction schema by name or ID.

        Parameters
        ----------
        name_or_id : str
            The name or the ID of the extraction schema to update.

        project : typing.Optional[str]
            The name of the project containing the extraction schema. Only used when `nameOrId` is a name.

        name : typing.Optional[str]
            A name for the extraction schema.

        prompt : typing.Optional[str]
            Instructions for how to extract data from conversations.

        fields : typing.Optional[typing.Sequence[ExtractionField]]
            Array of field definitions.

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

        Returns
        -------
        ExtractionSchemasUpdateResponse
            Success response

        Examples
        --------
        import asyncio

        from phonic import AsyncPhonic, ExtractionField

        client = AsyncPhonic(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.extraction_schemas.update(
                name_or_id="nameOrId",
                name="Updated appointment details",
                prompt="Updated extraction instructions. Dates should be in `9 Apr 2025` format.",
                fields=[
                    ExtractionField(
                        name="Date",
                        type="string",
                        description="The date of the appointment",
                    ),
                    ExtractionField(
                        name="Time",
                        type="string",
                        description="The time of the appointment",
                    ),
                ],
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update(
            name_or_id, project=project, name=name, prompt=prompt, fields=fields, request_options=request_options
        )
        return _response.data
