# 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 ..requests.classify_config import ClassifyConfigParams
from ..types.classify_run import ClassifyRun
from ..types.max_page_size import MaxPageSize
from ..types.next_page_token import NextPageToken
from ..types.processor_run_status import ProcessorRunStatus
from ..types.run_metadata import RunMetadata
from ..types.run_priority import RunPriority
from ..types.run_source import RunSource
from ..types.run_source_id import RunSourceId
from ..types.sort_by import SortBy
from ..types.sort_dir import SortDir
from .raw_client import AsyncRawClassifyRunsClient, RawClassifyRunsClient
from .requests.classify_runs_create_request_classifier import ClassifyRunsCreateRequestClassifierParams
from .requests.classify_runs_create_request_file import ClassifyRunsCreateRequestFileParams
from .types.classify_runs_delete_response import ClassifyRunsDeleteResponse
from .types.classify_runs_list_response import ClassifyRunsListResponse

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


class ClassifyRunsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawClassifyRunsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawClassifyRunsClient
        """
        return self._raw_client

    def list(
        self,
        *,
        status: typing.Optional[ProcessorRunStatus] = None,
        classifier_id: typing.Optional[str] = None,
        source_id: typing.Optional[RunSourceId] = None,
        source: typing.Optional[RunSource] = None,
        file_name_contains: typing.Optional[str] = None,
        sort_by: typing.Optional[SortBy] = None,
        sort_dir: typing.Optional[SortDir] = None,
        next_page_token: typing.Optional[NextPageToken] = None,
        max_page_size: typing.Optional[MaxPageSize] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ClassifyRunsListResponse:
        """
        List all classify runs.

        Returns a summary of each run. Use `GET /classify_runs/{id}` to retrieve the full object including `output` and `config`.

        Parameters
        ----------
        status : typing.Optional[ProcessorRunStatus]

        classifier_id : typing.Optional[str]
            Filters classify runs by the classifier ID. If not provided, all classify runs are returned.

            Example: `"cl_BMdfq_yWM3sT-ZzvCnA3f"`

        source_id : typing.Optional[RunSourceId]
            Filters runs by the source ID.

        source : typing.Optional[RunSource]
            Filters runs by the source that created them. If not provided, runs from all sources are returned.

        file_name_contains : typing.Optional[str]
            Filters runs by the name of the file. Only returns runs where the file name contains this string.

            Example: `"invoice"`

        sort_by : typing.Optional[SortBy]

        sort_dir : typing.Optional[SortDir]

        next_page_token : typing.Optional[NextPageToken]

        max_page_size : typing.Optional[MaxPageSize]

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

        Returns
        -------
        ClassifyRunsListResponse
            You will get a list of summaries for each classify run. These are shortened versions of the full classify run object.

            To get the full object, use the [Get Classify Run](https://docs.extend.ai/2026-02-09/developers/api-reference/endpoints/classify/get-classify-run) endpoint.

        Examples
        --------
        from extend_ai import Extend

        client = Extend(
            token="YOUR_TOKEN",
        )
        client.classify_runs.list(
            next_page_token="xK9mLPqRtN3vS8wF5hB2cQ==:zWvUxYjM4nKpL7aDgE9HbTcR2mAyX3/Q+CNkfBSw1dZ=",
        )
        """
        _response = self._raw_client.list(
            status=status,
            classifier_id=classifier_id,
            source_id=source_id,
            source=source,
            file_name_contains=file_name_contains,
            sort_by=sort_by,
            sort_dir=sort_dir,
            next_page_token=next_page_token,
            max_page_size=max_page_size,
            request_options=request_options,
        )
        return _response.data

    def create(
        self,
        *,
        file: ClassifyRunsCreateRequestFileParams,
        classifier: typing.Optional[ClassifyRunsCreateRequestClassifierParams] = OMIT,
        config: typing.Optional[ClassifyConfigParams] = OMIT,
        priority: typing.Optional[RunPriority] = OMIT,
        metadata: typing.Optional[RunMetadata] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ClassifyRun:
        """
        Classify a document using an existing classifier or an inline configuration.

        The request returns immediately with a `PROCESSING` status. Use webhooks or poll the Get Classify Run endpoint for results.

        Parameters
        ----------
        file : ClassifyRunsCreateRequestFileParams
            The file to be classified. Files can be provided as a URL, an Extend file ID, or raw text.

        classifier : typing.Optional[ClassifyRunsCreateRequestClassifierParams]
            Reference to an existing classifier. One of `classifier` or `config` must be provided.

        config : typing.Optional[ClassifyConfigParams]
            Inline classify configuration. One of `classifier` or `config` must be provided.

        priority : typing.Optional[RunPriority]

        metadata : typing.Optional[RunMetadata]

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

        Returns
        -------
        ClassifyRun
            Classification completed successfully

        Examples
        --------
        from extend_ai import Extend

        client = Extend(
            token="YOUR_TOKEN",
        )
        client.classify_runs.create(
            classifier={"id": "cl_1234567890"},
            file={"url": "https://example.com/document.pdf"},
        )
        """
        _response = self._raw_client.create(
            file=file,
            classifier=classifier,
            config=config,
            priority=priority,
            metadata=metadata,
            request_options=request_options,
        )
        return _response.data

    def retrieve(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> ClassifyRun:
        """
        Retrieve details about a specific classify run, including its status and outputs.

        A common use case for this endpoint is to poll for the status and final output of a classify run when using the [Create Classify Run](https://docs.extend.ai/2026-02-09/developers/api-reference/endpoints/classify/create-classify-run) endpoint. For instance, if you do not want to not configure webhooks to receive the output via completion/failure events.

        Parameters
        ----------
        id : str
            The unique identifier for this classify run.

            Example: `"cl_Xj8mK2pL9nR4vT7qY5wZ"`

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

        Returns
        -------
        ClassifyRun
            Successfully retrieved classify run

        Examples
        --------
        from extend_ai import Extend

        client = Extend(
            token="YOUR_TOKEN",
        )
        client.classify_runs.retrieve(
            id="classify_run_id_here",
        )
        """
        _response = self._raw_client.retrieve(id, request_options=request_options)
        return _response.data

    def delete(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> ClassifyRunsDeleteResponse:
        """
        Delete a classify run and all associated data from Extend. This operation is permanent and cannot be undone.

        This endpoint can be used if you'd like to manage data retention on your own rather than automated data retention policies. Or make one-off deletions for your downstream customers.

        Parameters
        ----------
        id : str
            The ID of the classify run.

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

        Returns
        -------
        ClassifyRunsDeleteResponse
            Classifier run deleted successfully

        Examples
        --------
        from extend_ai import Extend

        client = Extend(
            token="YOUR_TOKEN",
        )
        client.classify_runs.delete(
            id="id",
        )
        """
        _response = self._raw_client.delete(id, request_options=request_options)
        return _response.data

    def cancel(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> ClassifyRun:
        """
        Cancel an in-progress classify run.

        Note: Only classify runs with a status of `"PROCESSING"` can be cancelled. Classifier runs that have already completed, failed, or been cancelled cannot be cancelled again.

        Parameters
        ----------
        id : str
            The ID of the classify run to cancel.

            Example: `"cl_Xj8mK2pL9nR4vT7qY5wZ"`

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

        Returns
        -------
        ClassifyRun
            Classifier run cancelled successfully

        Examples
        --------
        from extend_ai import Extend

        client = Extend(
            token="YOUR_TOKEN",
        )
        client.classify_runs.cancel(
            id="classify_run_id_here",
        )
        """
        _response = self._raw_client.cancel(id, request_options=request_options)
        return _response.data


class AsyncClassifyRunsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawClassifyRunsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawClassifyRunsClient
        """
        return self._raw_client

    async def list(
        self,
        *,
        status: typing.Optional[ProcessorRunStatus] = None,
        classifier_id: typing.Optional[str] = None,
        source_id: typing.Optional[RunSourceId] = None,
        source: typing.Optional[RunSource] = None,
        file_name_contains: typing.Optional[str] = None,
        sort_by: typing.Optional[SortBy] = None,
        sort_dir: typing.Optional[SortDir] = None,
        next_page_token: typing.Optional[NextPageToken] = None,
        max_page_size: typing.Optional[MaxPageSize] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ClassifyRunsListResponse:
        """
        List all classify runs.

        Returns a summary of each run. Use `GET /classify_runs/{id}` to retrieve the full object including `output` and `config`.

        Parameters
        ----------
        status : typing.Optional[ProcessorRunStatus]

        classifier_id : typing.Optional[str]
            Filters classify runs by the classifier ID. If not provided, all classify runs are returned.

            Example: `"cl_BMdfq_yWM3sT-ZzvCnA3f"`

        source_id : typing.Optional[RunSourceId]
            Filters runs by the source ID.

        source : typing.Optional[RunSource]
            Filters runs by the source that created them. If not provided, runs from all sources are returned.

        file_name_contains : typing.Optional[str]
            Filters runs by the name of the file. Only returns runs where the file name contains this string.

            Example: `"invoice"`

        sort_by : typing.Optional[SortBy]

        sort_dir : typing.Optional[SortDir]

        next_page_token : typing.Optional[NextPageToken]

        max_page_size : typing.Optional[MaxPageSize]

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

        Returns
        -------
        ClassifyRunsListResponse
            You will get a list of summaries for each classify run. These are shortened versions of the full classify run object.

            To get the full object, use the [Get Classify Run](https://docs.extend.ai/2026-02-09/developers/api-reference/endpoints/classify/get-classify-run) endpoint.

        Examples
        --------
        import asyncio

        from extend_ai import AsyncExtend

        client = AsyncExtend(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.classify_runs.list(
                next_page_token="xK9mLPqRtN3vS8wF5hB2cQ==:zWvUxYjM4nKpL7aDgE9HbTcR2mAyX3/Q+CNkfBSw1dZ=",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.list(
            status=status,
            classifier_id=classifier_id,
            source_id=source_id,
            source=source,
            file_name_contains=file_name_contains,
            sort_by=sort_by,
            sort_dir=sort_dir,
            next_page_token=next_page_token,
            max_page_size=max_page_size,
            request_options=request_options,
        )
        return _response.data

    async def create(
        self,
        *,
        file: ClassifyRunsCreateRequestFileParams,
        classifier: typing.Optional[ClassifyRunsCreateRequestClassifierParams] = OMIT,
        config: typing.Optional[ClassifyConfigParams] = OMIT,
        priority: typing.Optional[RunPriority] = OMIT,
        metadata: typing.Optional[RunMetadata] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ClassifyRun:
        """
        Classify a document using an existing classifier or an inline configuration.

        The request returns immediately with a `PROCESSING` status. Use webhooks or poll the Get Classify Run endpoint for results.

        Parameters
        ----------
        file : ClassifyRunsCreateRequestFileParams
            The file to be classified. Files can be provided as a URL, an Extend file ID, or raw text.

        classifier : typing.Optional[ClassifyRunsCreateRequestClassifierParams]
            Reference to an existing classifier. One of `classifier` or `config` must be provided.

        config : typing.Optional[ClassifyConfigParams]
            Inline classify configuration. One of `classifier` or `config` must be provided.

        priority : typing.Optional[RunPriority]

        metadata : typing.Optional[RunMetadata]

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

        Returns
        -------
        ClassifyRun
            Classification completed successfully

        Examples
        --------
        import asyncio

        from extend_ai import AsyncExtend

        client = AsyncExtend(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.classify_runs.create(
                classifier={"id": "cl_1234567890"},
                file={"url": "https://example.com/document.pdf"},
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create(
            file=file,
            classifier=classifier,
            config=config,
            priority=priority,
            metadata=metadata,
            request_options=request_options,
        )
        return _response.data

    async def retrieve(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> ClassifyRun:
        """
        Retrieve details about a specific classify run, including its status and outputs.

        A common use case for this endpoint is to poll for the status and final output of a classify run when using the [Create Classify Run](https://docs.extend.ai/2026-02-09/developers/api-reference/endpoints/classify/create-classify-run) endpoint. For instance, if you do not want to not configure webhooks to receive the output via completion/failure events.

        Parameters
        ----------
        id : str
            The unique identifier for this classify run.

            Example: `"cl_Xj8mK2pL9nR4vT7qY5wZ"`

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

        Returns
        -------
        ClassifyRun
            Successfully retrieved classify run

        Examples
        --------
        import asyncio

        from extend_ai import AsyncExtend

        client = AsyncExtend(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.classify_runs.retrieve(
                id="classify_run_id_here",
            )


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

    async def delete(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ClassifyRunsDeleteResponse:
        """
        Delete a classify run and all associated data from Extend. This operation is permanent and cannot be undone.

        This endpoint can be used if you'd like to manage data retention on your own rather than automated data retention policies. Or make one-off deletions for your downstream customers.

        Parameters
        ----------
        id : str
            The ID of the classify run.

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

        Returns
        -------
        ClassifyRunsDeleteResponse
            Classifier run deleted successfully

        Examples
        --------
        import asyncio

        from extend_ai import AsyncExtend

        client = AsyncExtend(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.classify_runs.delete(
                id="id",
            )


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

    async def cancel(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> ClassifyRun:
        """
        Cancel an in-progress classify run.

        Note: Only classify runs with a status of `"PROCESSING"` can be cancelled. Classifier runs that have already completed, failed, or been cancelled cannot be cancelled again.

        Parameters
        ----------
        id : str
            The ID of the classify run to cancel.

            Example: `"cl_Xj8mK2pL9nR4vT7qY5wZ"`

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

        Returns
        -------
        ClassifyRun
            Classifier run cancelled successfully

        Examples
        --------
        import asyncio

        from extend_ai import AsyncExtend

        client = AsyncExtend(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.classify_runs.cancel(
                id="classify_run_id_here",
            )


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