# DO NOT EDIT — generated by _sdk_gen/ from the OpenAPI spec.
# Regenerate with: ./generate.sh
from __future__ import annotations

from typing import Any

import httpx

from goodmem._generated.models.ocr_document_request import OcrDocumentRequest
from goodmem._generated.models.ocr_document_response import OcrDocumentResponse
from goodmem.errors import raise_for_status


class OcrAPIBase:
    """Ocr API — auto-generated structural base.

    Auto-generated structural base. Do not edit.
    Override in goodmem/api/ocr.py to add domain-specific logic.
    """

    _rest_metadata: dict = {'document': {'http_method': 'POST', 'path': '/v1/ocr:document', 'response': 'OcrDocumentResponse', 'body_model': 'OcrDocumentRequest', 'body_expr': 'OcrDocumentRequest(**kwargs)', 'body_kind': 'json', 'body_kinds': ['application/json']}}

    def __init__(self, http: httpx.Client, headers: dict[str, str]) -> None:
        self._http = http
        self._headers = headers

    def document(self, *, content, format=None, include_raw_json=None, include_markdown=None, start_page=None, end_page=None, **kwargs: Any) -> OcrDocumentResponse:
        """Run OCR on a document or image

        Runs layout-aware OCR on the provided document bytes and returns per-page results. When a page range is provided, only the inclusive subset is processed. Requires OCR_DOCUMENT permission.

        Args:
            content (string): Base64-encoded document bytes
            format (OcrInputFormat, optional): Input format hint (AUTO, PDF, TIFF, PNG, JPEG, BMP)
            include_raw_json (boolean, optional): Include raw OCR JSON payload in the response
            include_markdown (boolean, optional): Include markdown rendering in the response
            start_page (integer, optional): 0-based inclusive start page
            end_page (integer, optional): 0-based inclusive end page

        Returns:
            OcrDocumentResponse
        """
        _params = {**kwargs}
        _params['content'] = content
        if format is not None:
            _params['format'] = format
        if include_raw_json is not None:
            _params['include_raw_json'] = include_raw_json
        if include_markdown is not None:
            _params['include_markdown'] = include_markdown
        if start_page is not None:
            _params['start_page'] = start_page
        if end_page is not None:
            _params['end_page'] = end_page
        body = OcrDocumentRequest.model_validate(_params)
        resp = self._http.post(
            "/v1/ocr:document",
            json=body.model_dump(by_alias=True, exclude_unset=True),
            headers=self._headers,
        )
        raise_for_status(resp)
        return OcrDocumentResponse.model_validate(resp.json())


class AsyncOcrAPIBase:
    """Async Ocr API — auto-generated structural base.

    Auto-generated structural base. Do not edit.
    Override in goodmem/api/ocr.py to add domain-specific logic.
    """

    _rest_metadata: dict = {'document': {'http_method': 'POST', 'path': '/v1/ocr:document', 'response': 'OcrDocumentResponse', 'body_model': 'OcrDocumentRequest', 'body_expr': 'OcrDocumentRequest(**kwargs)', 'body_kind': 'json', 'body_kinds': ['application/json']}}

    def __init__(self, http: httpx.AsyncClient, headers: dict[str, str]) -> None:
        self._http = http
        self._headers = headers

    async def document(self, *, content, format=None, include_raw_json=None, include_markdown=None, start_page=None, end_page=None, **kwargs: Any) -> OcrDocumentResponse:
        """Run OCR on a document or image

        Runs layout-aware OCR on the provided document bytes and returns per-page results. When a page range is provided, only the inclusive subset is processed. Requires OCR_DOCUMENT permission.

        Args:
            content (string): Base64-encoded document bytes
            format (OcrInputFormat, optional): Input format hint (AUTO, PDF, TIFF, PNG, JPEG, BMP)
            include_raw_json (boolean, optional): Include raw OCR JSON payload in the response
            include_markdown (boolean, optional): Include markdown rendering in the response
            start_page (integer, optional): 0-based inclusive start page
            end_page (integer, optional): 0-based inclusive end page

        Returns:
            OcrDocumentResponse
        """
        _params = {**kwargs}
        _params['content'] = content
        if format is not None:
            _params['format'] = format
        if include_raw_json is not None:
            _params['include_raw_json'] = include_raw_json
        if include_markdown is not None:
            _params['include_markdown'] = include_markdown
        if start_page is not None:
            _params['start_page'] = start_page
        if end_page is not None:
            _params['end_page'] = end_page
        body = OcrDocumentRequest.model_validate(_params)
        resp = await self._http.post(
            "/v1/ocr:document",
            json=body.model_dump(by_alias=True, exclude_unset=True),
            headers=self._headers,
        )
        raise_for_status(resp)
        return OcrDocumentResponse.model_validate(resp.json())

