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

import typing

from .. import core
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from ..types.image_analyze_response import ImageAnalyzeResponse
from .raw_client import AsyncRawVisionClient, RawVisionClient

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


class VisionClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawVisionClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawVisionClient
        """
        return self._raw_client

    def analyze_image(
        self,
        *,
        image_file: core.File,
        schema: str,
        organization_id: str,
        prompt: typing.Optional[str] = OMIT,
        model: typing.Optional[str] = OMIT,
        provider: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ImageAnalyzeResponse:
        """
        Analyze image and extract structured data using OpenAI Vision API.

            **Supported Providers:**
            - `openai`: GPT-5 Vision API (Aug 2025+)

            **Parameters:**
            - `image_file`: Image to analyze (PNG, JPEG, WebP)
            - `schema`: JSON schema defining extraction structure
            - `organization_id`: Organization ID (org_ prefixed string)
            - `prompt`: Optional custom instructions (e.g., "Focus on text in the center", "Ignore watermarks")
            - `model`: GPT-5 model to use (gpt-5 standard, gpt-5.1 latest, gpt-5-turbo fast, gpt-5-mini cost-effective)
            - `provider`: Provider to use (currently only openai)

            **Model Selection (GPT-5 Series Only):**
            - `gpt-5`: Standard model - best balance of quality and speed (~$0.03 per image)
            - `gpt-5.1`: Latest iteration (Nov 2025) - faster, customizable personalities (~$0.03 per image)
            - `gpt-5-turbo`: Optimized for speed while maintaining quality (~$0.02 per image)
            - `gpt-5-mini`: Fast and cost-effective for simple tasks (~$0.01 per image)

            **Use Cases:**
            - Extract data from photos
            - Analyze screenshots
            - Process scanned documents
            - OCR with structured output
            - Invoice/receipt processing

            **Billing:**
            - Cost: ~$0.01-0.03 per image (depends on GPT-5 variant)
            - Tracked through usage_events system

            **Response Headers:**
            - `X-Provider`: Provider that processed the request
            - `X-Model-Used`: Actual model used
            - `X-Cost-CHF`: Total cost in CHF

        Parameters
        ----------
        image_file : core.File
            See core.File for more documentation

        schema : str
            JSON schema defining extraction structure

        organization_id : str
            Organization ID (org_ prefixed string)

        prompt : typing.Optional[str]
            Optional custom instructions for analysis

        model : typing.Optional[str]
            GPT-5 model to use (gpt-5 standard, gpt-5.1 latest, gpt-5-turbo fast, gpt-5-mini cost-effective)

        provider : typing.Optional[str]
            Provider to use (currently only openai)

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

        Returns
        -------
        ImageAnalyzeResponse
            Image analyzed successfully

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.vision.analyze_image(
            schema="schema",
            organization_id="organization_id",
        )
        """
        _response = self._raw_client.analyze_image(
            image_file=image_file,
            schema=schema,
            organization_id=organization_id,
            prompt=prompt,
            model=model,
            provider=provider,
            request_options=request_options,
        )
        return _response.data


class AsyncVisionClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawVisionClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawVisionClient
        """
        return self._raw_client

    async def analyze_image(
        self,
        *,
        image_file: core.File,
        schema: str,
        organization_id: str,
        prompt: typing.Optional[str] = OMIT,
        model: typing.Optional[str] = OMIT,
        provider: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ImageAnalyzeResponse:
        """
        Analyze image and extract structured data using OpenAI Vision API.

            **Supported Providers:**
            - `openai`: GPT-5 Vision API (Aug 2025+)

            **Parameters:**
            - `image_file`: Image to analyze (PNG, JPEG, WebP)
            - `schema`: JSON schema defining extraction structure
            - `organization_id`: Organization ID (org_ prefixed string)
            - `prompt`: Optional custom instructions (e.g., "Focus on text in the center", "Ignore watermarks")
            - `model`: GPT-5 model to use (gpt-5 standard, gpt-5.1 latest, gpt-5-turbo fast, gpt-5-mini cost-effective)
            - `provider`: Provider to use (currently only openai)

            **Model Selection (GPT-5 Series Only):**
            - `gpt-5`: Standard model - best balance of quality and speed (~$0.03 per image)
            - `gpt-5.1`: Latest iteration (Nov 2025) - faster, customizable personalities (~$0.03 per image)
            - `gpt-5-turbo`: Optimized for speed while maintaining quality (~$0.02 per image)
            - `gpt-5-mini`: Fast and cost-effective for simple tasks (~$0.01 per image)

            **Use Cases:**
            - Extract data from photos
            - Analyze screenshots
            - Process scanned documents
            - OCR with structured output
            - Invoice/receipt processing

            **Billing:**
            - Cost: ~$0.01-0.03 per image (depends on GPT-5 variant)
            - Tracked through usage_events system

            **Response Headers:**
            - `X-Provider`: Provider that processed the request
            - `X-Model-Used`: Actual model used
            - `X-Cost-CHF`: Total cost in CHF

        Parameters
        ----------
        image_file : core.File
            See core.File for more documentation

        schema : str
            JSON schema defining extraction structure

        organization_id : str
            Organization ID (org_ prefixed string)

        prompt : typing.Optional[str]
            Optional custom instructions for analysis

        model : typing.Optional[str]
            GPT-5 model to use (gpt-5 standard, gpt-5.1 latest, gpt-5-turbo fast, gpt-5-mini cost-effective)

        provider : typing.Optional[str]
            Provider to use (currently only openai)

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

        Returns
        -------
        ImageAnalyzeResponse
            Image analyzed successfully

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.vision.analyze_image(
                schema="schema",
                organization_id="organization_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.analyze_image(
            image_file=image_file,
            schema=schema,
            organization_id=organization_id,
            prompt=prompt,
            model=model,
            provider=provider,
            request_options=request_options,
        )
        return _response.data
