# coding: utf-8

"""
    AI Stats Gateway API

    A gateway API for accessing various AI models with OpenAI-compatible endpoints.

    The version of the OpenAPI document: 1.0.0
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing_extensions import Annotated
from ai_stats_generated.models.chat_completions_request_tool_choice import ChatCompletionsRequestToolChoice
from ai_stats_generated.models.responses_request_prompt import ResponsesRequestPrompt
from ai_stats_generated.models.responses_request_reasoning import ResponsesRequestReasoning
from typing import Optional, Set
from typing_extensions import Self

class ResponsesRequest(BaseModel):
    """
    ResponsesRequest
    """ # noqa: E501
    model: StrictStr
    input: Optional[Dict[str, Any]] = None
    input_items: Optional[List[Dict[str, Any]]] = None
    conversation: Optional[ChatCompletionsRequestToolChoice] = None
    include: Optional[List[StrictStr]] = None
    instructions: Optional[StrictStr] = None
    max_output_tokens: Optional[Annotated[int, Field(strict=True, ge=1)]] = None
    max_tool_calls: Optional[Annotated[int, Field(strict=True, ge=0)]] = None
    metadata: Optional[Dict[str, StrictStr]] = None
    parallel_tool_calls: Optional[StrictBool] = None
    previous_response_id: Optional[StrictStr] = None
    prompt: Optional[ResponsesRequestPrompt] = None
    prompt_cache_key: Optional[StrictStr] = None
    prompt_cache_retention: Optional[StrictStr] = None
    reasoning: Optional[ResponsesRequestReasoning] = None
    safety_identifier: Optional[StrictStr] = None
    service_tier: Optional[StrictStr] = None
    store: Optional[StrictBool] = None
    stream: Optional[StrictBool] = None
    stream_options: Optional[Dict[str, Any]] = None
    temperature: Optional[Union[Annotated[float, Field(le=2, strict=True, ge=0)], Annotated[int, Field(le=2, strict=True, ge=0)]]] = None
    text: Optional[Dict[str, Any]] = None
    tool_choice: Optional[ChatCompletionsRequestToolChoice] = None
    tools: Optional[List[Dict[str, Any]]] = None
    top_logprobs: Optional[Annotated[int, Field(le=20, strict=True, ge=0)]] = None
    top_p: Optional[Union[Annotated[float, Field(le=1, strict=True, ge=0)], Annotated[int, Field(le=1, strict=True, ge=0)]]] = None
    truncation: Optional[StrictStr] = None
    background: Optional[StrictBool] = None
    user: Optional[StrictStr] = None
    usage: Optional[StrictBool] = None
    meta: Optional[StrictBool] = None
    __properties: ClassVar[List[str]] = ["model", "input", "input_items", "conversation", "include", "instructions", "max_output_tokens", "max_tool_calls", "metadata", "parallel_tool_calls", "previous_response_id", "prompt", "prompt_cache_key", "prompt_cache_retention", "reasoning", "safety_identifier", "service_tier", "store", "stream", "stream_options", "temperature", "text", "tool_choice", "tools", "top_logprobs", "top_p", "truncation", "background", "user", "usage", "meta"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of ResponsesRequest from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of conversation
        if self.conversation:
            _dict['conversation'] = self.conversation.to_dict()
        # override the default output from pydantic by calling `to_dict()` of prompt
        if self.prompt:
            _dict['prompt'] = self.prompt.to_dict()
        # override the default output from pydantic by calling `to_dict()` of reasoning
        if self.reasoning:
            _dict['reasoning'] = self.reasoning.to_dict()
        # override the default output from pydantic by calling `to_dict()` of tool_choice
        if self.tool_choice:
            _dict['tool_choice'] = self.tool_choice.to_dict()
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of ResponsesRequest from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "model": obj.get("model"),
            "input": obj.get("input"),
            "input_items": obj.get("input_items"),
            "conversation": ChatCompletionsRequestToolChoice.from_dict(obj["conversation"]) if obj.get("conversation") is not None else None,
            "include": obj.get("include"),
            "instructions": obj.get("instructions"),
            "max_output_tokens": obj.get("max_output_tokens"),
            "max_tool_calls": obj.get("max_tool_calls"),
            "metadata": obj.get("metadata"),
            "parallel_tool_calls": obj.get("parallel_tool_calls"),
            "previous_response_id": obj.get("previous_response_id"),
            "prompt": ResponsesRequestPrompt.from_dict(obj["prompt"]) if obj.get("prompt") is not None else None,
            "prompt_cache_key": obj.get("prompt_cache_key"),
            "prompt_cache_retention": obj.get("prompt_cache_retention"),
            "reasoning": ResponsesRequestReasoning.from_dict(obj["reasoning"]) if obj.get("reasoning") is not None else None,
            "safety_identifier": obj.get("safety_identifier"),
            "service_tier": obj.get("service_tier"),
            "store": obj.get("store"),
            "stream": obj.get("stream"),
            "stream_options": obj.get("stream_options"),
            "temperature": obj.get("temperature"),
            "text": obj.get("text"),
            "tool_choice": ChatCompletionsRequestToolChoice.from_dict(obj["tool_choice"]) if obj.get("tool_choice") is not None else None,
            "tools": obj.get("tools"),
            "top_logprobs": obj.get("top_logprobs"),
            "top_p": obj.get("top_p"),
            "truncation": obj.get("truncation"),
            "background": obj.get("background"),
            "user": obj.get("user"),
            "usage": obj.get("usage"),
            "meta": obj.get("meta")
        })
        return _obj


