# 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_schema_generation_config import EditSchemaGenerationConfigParams
from ..types.edit_schema_generation_response import EditSchemaGenerationResponse
from .raw_client import AsyncRawEditSchemasClient, RawEditSchemasClient
from .requests.edit_schemas_generate_request_file import EditSchemasGenerateRequestFileParams

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


class EditSchemasClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawEditSchemasClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawEditSchemasClient
        """
        return self._raw_client

    def generate(
        self,
        *,
        file: EditSchemasGenerateRequestFileParams,
        config: typing.Optional[EditSchemaGenerationConfigParams] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EditSchemaGenerationResponse:
        """
        Detect fields in a PDF form and synchronously return an edit schema payload.

        Use this endpoint when you want Extend to bootstrap an `EditRootJSON` schema from an existing form, optionally mapping an existing schema onto the detected fields.

        This endpoint returns the generated schema directly. There are no schema generation run resources to poll or delete.

        For more details, see the [Generate Edit Schema guide](https://docs.extend.ai/2026-02-09/product/editing/generate-edit-schema) and the [Edit File guide](https://docs.extend.ai/2026-02-09/product/editing/edit).

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

        config : typing.Optional[EditSchemaGenerationConfigParams]

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

        Returns
        -------
        EditSchemaGenerationResponse
            Successfully generated edit schema

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

        client = Extend(
            token="YOUR_TOKEN",
        )
        client.edit_schemas.generate(
            file={"url": "https://example.com/form.pdf"},
            config={
                "instructions": "Detect the form fields and use human-readable field names.",
                "advanced_options": {"radio_enums_enabled": True},
            },
        )
        """
        _response = self._raw_client.generate(file=file, config=config, request_options=request_options)
        return _response.data


class AsyncEditSchemasClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawEditSchemasClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawEditSchemasClient
        """
        return self._raw_client

    async def generate(
        self,
        *,
        file: EditSchemasGenerateRequestFileParams,
        config: typing.Optional[EditSchemaGenerationConfigParams] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EditSchemaGenerationResponse:
        """
        Detect fields in a PDF form and synchronously return an edit schema payload.

        Use this endpoint when you want Extend to bootstrap an `EditRootJSON` schema from an existing form, optionally mapping an existing schema onto the detected fields.

        This endpoint returns the generated schema directly. There are no schema generation run resources to poll or delete.

        For more details, see the [Generate Edit Schema guide](https://docs.extend.ai/2026-02-09/product/editing/generate-edit-schema) and the [Edit File guide](https://docs.extend.ai/2026-02-09/product/editing/edit).

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

        config : typing.Optional[EditSchemaGenerationConfigParams]

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

        Returns
        -------
        EditSchemaGenerationResponse
            Successfully generated edit schema

        Examples
        --------
        import asyncio

        from extend_ai import AsyncExtend

        client = AsyncExtend(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.edit_schemas.generate(
                file={"url": "https://example.com/form.pdf"},
                config={
                    "instructions": "Detect the form fields and use human-readable field names.",
                    "advanced_options": {"radio_enums_enabled": True},
                },
            )


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