# This file was auto-generated by Fern from our API Definition.

import typing
import uuid

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from .raw_client import AsyncRawOcrClient, RawOcrClient
from .types.ocr_job_response import OcrJobResponse
from .types.ocr_job_status import OcrJobStatus

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


class OcrClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawOcrClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawOcrClient
        """
        return self._raw_client

    def create_ocr_job(
        self,
        *,
        storage_path: str,
        job_id: typing.Optional[uuid.UUID] = OMIT,
        file_name: typing.Optional[str] = OMIT,
        content_type: typing.Optional[str] = OMIT,
        file_kind: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> OcrJobResponse:
        """
        Create an OCR job for a file already uploaded to Supabase Storage.

        Parameters
        ----------
        storage_path : str
            Path to the uploaded file within the OCR storage bucket.

        job_id : typing.Optional[uuid.UUID]
            Optional job id. Provide this when you pre-allocate a storage path using the job id.

        file_name : typing.Optional[str]
            Original file name.

        content_type : typing.Optional[str]
            MIME type of the uploaded file (e.g., application/pdf, image/png).

        file_kind : typing.Optional[str]
            Optional hint for file type (pdf or image).

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

        Returns
        -------
        OcrJobResponse

        Examples
        --------
        from soferai import SoferAI

        client = SoferAI(
            api_key="YOUR_API_KEY",
        )
        client.ocr.create_ocr_job(
            storage_path="storage_path",
        )
        """
        _response = self._raw_client.create_ocr_job(
            storage_path=storage_path,
            job_id=job_id,
            file_name=file_name,
            content_type=content_type,
            file_kind=file_kind,
            request_options=request_options,
        )
        return _response.data

    def get_ocr_job(
        self, job_id: uuid.UUID, *, request_options: typing.Optional[RequestOptions] = None
    ) -> OcrJobStatus:
        """
        Get OCR job status and extracted text for each page.

        Parameters
        ----------
        job_id : uuid.UUID
            OCR job id.

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

        Returns
        -------
        OcrJobStatus

        Examples
        --------
        import uuid

        from soferai import SoferAI

        client = SoferAI(
            api_key="YOUR_API_KEY",
        )
        client.ocr.get_ocr_job(
            job_id=uuid.UUID(
                "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
            ),
        )
        """
        _response = self._raw_client.get_ocr_job(job_id, request_options=request_options)
        return _response.data


class AsyncOcrClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawOcrClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawOcrClient
        """
        return self._raw_client

    async def create_ocr_job(
        self,
        *,
        storage_path: str,
        job_id: typing.Optional[uuid.UUID] = OMIT,
        file_name: typing.Optional[str] = OMIT,
        content_type: typing.Optional[str] = OMIT,
        file_kind: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> OcrJobResponse:
        """
        Create an OCR job for a file already uploaded to Supabase Storage.

        Parameters
        ----------
        storage_path : str
            Path to the uploaded file within the OCR storage bucket.

        job_id : typing.Optional[uuid.UUID]
            Optional job id. Provide this when you pre-allocate a storage path using the job id.

        file_name : typing.Optional[str]
            Original file name.

        content_type : typing.Optional[str]
            MIME type of the uploaded file (e.g., application/pdf, image/png).

        file_kind : typing.Optional[str]
            Optional hint for file type (pdf or image).

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

        Returns
        -------
        OcrJobResponse

        Examples
        --------
        import asyncio

        from soferai import AsyncSoferAI

        client = AsyncSoferAI(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.ocr.create_ocr_job(
                storage_path="storage_path",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_ocr_job(
            storage_path=storage_path,
            job_id=job_id,
            file_name=file_name,
            content_type=content_type,
            file_kind=file_kind,
            request_options=request_options,
        )
        return _response.data

    async def get_ocr_job(
        self, job_id: uuid.UUID, *, request_options: typing.Optional[RequestOptions] = None
    ) -> OcrJobStatus:
        """
        Get OCR job status and extracted text for each page.

        Parameters
        ----------
        job_id : uuid.UUID
            OCR job id.

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

        Returns
        -------
        OcrJobStatus

        Examples
        --------
        import asyncio
        import uuid

        from soferai import AsyncSoferAI

        client = AsyncSoferAI(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.ocr.get_ocr_job(
                job_id=uuid.UUID(
                    "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                ),
            )


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