# 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.edit_config import EditConfigParams
from ..types.edit_run import EditRun
from .raw_client import AsyncRawEditRunsClient, RawEditRunsClient
from .requests.edit_runs_create_request_file import EditRunsCreateRequestFileParams
from .types.edit_runs_delete_response import EditRunsDeleteResponse

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


class EditRunsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawEditRunsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawEditRunsClient
        """
        return self._raw_client

    def create(
        self,
        *,
        file: EditRunsCreateRequestFileParams,
        config: typing.Optional[EditConfigParams] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EditRun:
        """
        Edit and manipulate PDF documents by detecting and filling form fields.

        The Edit Runs endpoint allows you to convert and edit documents and get an edit run ID that can be used to check status and retrieve results with the Get Edit Run endpoint.

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

        Parameters
        ----------
        file : EditRunsCreateRequestFileParams
            The file to be edited. Files can be provided as a URL or an Extend file ID.

        config : typing.Optional[EditConfigParams]

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

        Returns
        -------
        EditRun
            Successfully initiated edit run

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

        client = Extend(
            token="YOUR_TOKEN",
        )
        client.edit_runs.create(
            file={"url": "https://example.com/form.pdf"},
            config={
                "instructions": "Fill out the form with the provided data",
                "advanced_options": {"flatten_pdf": True},
            },
        )
        """
        _response = self._raw_client.create(file=file, config=config, request_options=request_options)
        return _response.data

    def retrieve(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> EditRun:
        """
        Retrieve the status and results of an edit run.

        Use this endpoint to get results for an edit run that has already completed, or to check on the status of an edit run initiated via the [Create Edit Run](https://docs.extend.ai/2026-02-09/developers/api-reference/endpoints/edit/create-edit-run) endpoint.

        Parameters
        ----------
        id : str
            The unique identifier for the edit run.

            Example: `"edr_xK9mLPqRtN3vS8wF5hB2cQ"`

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

        Returns
        -------
        EditRun
            Successfully retrieved edit run

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

        client = Extend(
            token="YOUR_TOKEN",
        )
        client.edit_runs.retrieve(
            id="edit_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) -> EditRunsDeleteResponse:
        """
        Delete an edit 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 relying on automated data retention policies, or to make one-off deletions for your downstream customers.

        Parameters
        ----------
        id : str
            The ID of the edit run to delete.

            Example: `"edr_xK9mLPqRtN3vS8wF5hB2cQ"`

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

        Returns
        -------
        EditRunsDeleteResponse
            Successfully deleted edit run

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

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


class AsyncEditRunsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawEditRunsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawEditRunsClient
        """
        return self._raw_client

    async def create(
        self,
        *,
        file: EditRunsCreateRequestFileParams,
        config: typing.Optional[EditConfigParams] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EditRun:
        """
        Edit and manipulate PDF documents by detecting and filling form fields.

        The Edit Runs endpoint allows you to convert and edit documents and get an edit run ID that can be used to check status and retrieve results with the Get Edit Run endpoint.

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

        Parameters
        ----------
        file : EditRunsCreateRequestFileParams
            The file to be edited. Files can be provided as a URL or an Extend file ID.

        config : typing.Optional[EditConfigParams]

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

        Returns
        -------
        EditRun
            Successfully initiated edit run

        Examples
        --------
        import asyncio

        from extend_ai import AsyncExtend

        client = AsyncExtend(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.edit_runs.create(
                file={"url": "https://example.com/form.pdf"},
                config={
                    "instructions": "Fill out the form with the provided data",
                    "advanced_options": {"flatten_pdf": True},
                },
            )


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

    async def retrieve(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> EditRun:
        """
        Retrieve the status and results of an edit run.

        Use this endpoint to get results for an edit run that has already completed, or to check on the status of an edit run initiated via the [Create Edit Run](https://docs.extend.ai/2026-02-09/developers/api-reference/endpoints/edit/create-edit-run) endpoint.

        Parameters
        ----------
        id : str
            The unique identifier for the edit run.

            Example: `"edr_xK9mLPqRtN3vS8wF5hB2cQ"`

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

        Returns
        -------
        EditRun
            Successfully retrieved edit run

        Examples
        --------
        import asyncio

        from extend_ai import AsyncExtend

        client = AsyncExtend(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.edit_runs.retrieve(
                id="edit_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
    ) -> EditRunsDeleteResponse:
        """
        Delete an edit 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 relying on automated data retention policies, or to make one-off deletions for your downstream customers.

        Parameters
        ----------
        id : str
            The ID of the edit run to delete.

            Example: `"edr_xK9mLPqRtN3vS8wF5hB2cQ"`

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

        Returns
        -------
        EditRunsDeleteResponse
            Successfully deleted edit run

        Examples
        --------
        import asyncio

        from extend_ai import AsyncExtend

        client = AsyncExtend(
            token="YOUR_TOKEN",
        )


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


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