# 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.edit_run import EditRun
from ..types.edit_run_status import EditRunStatus
from .raw_client import AsyncRawEditClient, RawEditClient
from .types.edit_create_async_request_config import EditCreateAsyncRequestConfig
from .types.edit_create_async_request_file import EditCreateAsyncRequestFile
from .types.edit_create_request_config import EditCreateRequestConfig
from .types.edit_create_request_file import EditCreateRequestFile
from .types.edit_delete_response import EditDeleteResponse
from .types.edit_get_response import EditGetResponse

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


class EditClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawEditClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawEditClient
        """
        return self._raw_client

    def create(
        self,
        *,
        file: EditCreateRequestFile,
        config: typing.Optional[EditCreateRequestConfig] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EditRun:
        """
        Edit and manipulate PDF documents by detecting and filling form fields.
        This is a synchronous endpoint that will wait for the edit operation to complete (up to 5 minutes) before returning results. For longer operations, use the [Edit File Async](/developers/api-reference/edit-endpoints/edit-file-async) endpoint.

        Parameters
        ----------
        file : EditCreateRequestFile
            A file object containing either a URL or a fileId.

        config : typing.Optional[EditCreateRequestConfig]
            Configuration for the edit operation. Field values should be specified using `extend_edit:value` on each field in the schema.

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

        Returns
        -------
        EditRun
            Successfully edited file

        Examples
        --------
        from extend_ai import Extend
        from extend_ai.edit import EditCreateRequestFile

        client = Extend(
            token="YOUR_TOKEN",
        )
        client.edit.create(
            file=EditCreateRequestFile(),
        )
        """
        _response = self._raw_client.create(file=file, config=config, request_options=request_options)
        return _response.data

    def create_async(
        self,
        *,
        file: EditCreateAsyncRequestFile,
        config: typing.Optional[EditCreateAsyncRequestConfig] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EditRunStatus:
        """
        Edit and manipulate PDF documents **asynchronously** by filling forms, adding/modifying text fields, and applying structured changes.

        The Edit Async endpoint allows you to convert and edit documents asynchronously and get an edit run ID that can be used to check status and retrieve results with the [Get Edit Run](/developers/api-reference/edit-endpoints/get-edit-run) endpoint.

        This is useful for:
        * Large files that may take longer to process
        * Avoiding timeout issues with synchronous editing
        * Processing multiple files in parallel

        Parameters
        ----------
        file : EditCreateAsyncRequestFile
            A file object containing either a URL or a fileId.

        config : typing.Optional[EditCreateAsyncRequestConfig]
            Configuration for the edit operation. Field values should be specified using `extend_edit:value` on each field in the schema.

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

        Returns
        -------
        EditRunStatus
            Successfully initiated edit run

        Examples
        --------
        from extend_ai import Extend
        from extend_ai.edit import EditCreateAsyncRequestFile

        client = Extend(
            token="YOUR_TOKEN",
        )
        client.edit.create_async(
            file=EditCreateAsyncRequestFile(),
        )
        """
        _response = self._raw_client.create_async(file=file, config=config, request_options=request_options)
        return _response.data

    def get(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> EditGetResponse:
        """
        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 asynchronous edit run initiated via the [Edit File Asynchronously](/developers/api-reference/edit-endpoints/edit-file-async) endpoint.

        If editing is still in progress, you'll receive a response with just the status. Once complete, you'll receive the full edited file information in the response.

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

            Example: `"edit_run_xK9mLPqRtN3vS8wF5hB2cQ"`

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

        Returns
        -------
        EditGetResponse
            Successfully retrieved edit run

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

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

    def delete(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> EditDeleteResponse:
        """
        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: `"edit_run_xK9mLPqRtN3vS8wF5hB2cQ"`

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

        Returns
        -------
        EditDeleteResponse
            Successfully deleted edit run

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

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


class AsyncEditClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawEditClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawEditClient
        """
        return self._raw_client

    async def create(
        self,
        *,
        file: EditCreateRequestFile,
        config: typing.Optional[EditCreateRequestConfig] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EditRun:
        """
        Edit and manipulate PDF documents by detecting and filling form fields.
        This is a synchronous endpoint that will wait for the edit operation to complete (up to 5 minutes) before returning results. For longer operations, use the [Edit File Async](/developers/api-reference/edit-endpoints/edit-file-async) endpoint.

        Parameters
        ----------
        file : EditCreateRequestFile
            A file object containing either a URL or a fileId.

        config : typing.Optional[EditCreateRequestConfig]
            Configuration for the edit operation. Field values should be specified using `extend_edit:value` on each field in the schema.

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

        Returns
        -------
        EditRun
            Successfully edited file

        Examples
        --------
        import asyncio

        from extend_ai import AsyncExtend
        from extend_ai.edit import EditCreateRequestFile

        client = AsyncExtend(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.edit.create(
                file=EditCreateRequestFile(),
            )


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

    async def create_async(
        self,
        *,
        file: EditCreateAsyncRequestFile,
        config: typing.Optional[EditCreateAsyncRequestConfig] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EditRunStatus:
        """
        Edit and manipulate PDF documents **asynchronously** by filling forms, adding/modifying text fields, and applying structured changes.

        The Edit Async endpoint allows you to convert and edit documents asynchronously and get an edit run ID that can be used to check status and retrieve results with the [Get Edit Run](/developers/api-reference/edit-endpoints/get-edit-run) endpoint.

        This is useful for:
        * Large files that may take longer to process
        * Avoiding timeout issues with synchronous editing
        * Processing multiple files in parallel

        Parameters
        ----------
        file : EditCreateAsyncRequestFile
            A file object containing either a URL or a fileId.

        config : typing.Optional[EditCreateAsyncRequestConfig]
            Configuration for the edit operation. Field values should be specified using `extend_edit:value` on each field in the schema.

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

        Returns
        -------
        EditRunStatus
            Successfully initiated edit run

        Examples
        --------
        import asyncio

        from extend_ai import AsyncExtend
        from extend_ai.edit import EditCreateAsyncRequestFile

        client = AsyncExtend(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.edit.create_async(
                file=EditCreateAsyncRequestFile(),
            )


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

    async def get(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> EditGetResponse:
        """
        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 asynchronous edit run initiated via the [Edit File Asynchronously](/developers/api-reference/edit-endpoints/edit-file-async) endpoint.

        If editing is still in progress, you'll receive a response with just the status. Once complete, you'll receive the full edited file information in the response.

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

            Example: `"edit_run_xK9mLPqRtN3vS8wF5hB2cQ"`

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

        Returns
        -------
        EditGetResponse
            Successfully retrieved edit run

        Examples
        --------
        import asyncio

        from extend_ai import AsyncExtend

        client = AsyncExtend(
            token="YOUR_TOKEN",
        )


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


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

    async def delete(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> EditDeleteResponse:
        """
        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: `"edit_run_xK9mLPqRtN3vS8wF5hB2cQ"`

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

        Returns
        -------
        EditDeleteResponse
            Successfully deleted edit run

        Examples
        --------
        import asyncio

        from extend_ai import AsyncExtend

        client = AsyncExtend(
            token="YOUR_TOKEN",
        )


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


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