# 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, StrictBool, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from ai_stats_generated.models.generation_response_usage import GenerationResponseUsage
from typing import Optional, Set
from typing_extensions import Self

class GenerationResponse(BaseModel):
    """
    GenerationResponse
    """ # noqa: E501
    request_id: Optional[StrictStr] = None
    team_id: Optional[StrictStr] = None
    app_id: Optional[StrictStr] = None
    endpoint: Optional[StrictStr] = None
    model_id: Optional[StrictStr] = None
    provider: Optional[StrictStr] = None
    native_response_id: Optional[StrictStr] = None
    stream: Optional[StrictBool] = None
    byok: Optional[StrictBool] = None
    status_code: Optional[Union[StrictFloat, StrictInt]] = None
    success: Optional[StrictBool] = None
    error_code: Optional[StrictStr] = None
    error_message: Optional[StrictStr] = None
    latency_ms: Optional[Union[StrictFloat, StrictInt]] = None
    generation_ms: Optional[Union[StrictFloat, StrictInt]] = None
    usage: Optional[GenerationResponseUsage] = None
    cost_nanos: Optional[Union[StrictFloat, StrictInt]] = None
    currency: Optional[StrictStr] = None
    pricing_lines: Optional[List[Dict[str, Any]]] = None
    key_id: Optional[StrictStr] = None
    throughput: Optional[Union[StrictFloat, StrictInt]] = None
    __properties: ClassVar[List[str]] = ["request_id", "team_id", "app_id", "endpoint", "model_id", "provider", "native_response_id", "stream", "byok", "status_code", "success", "error_code", "error_message", "latency_ms", "generation_ms", "usage", "cost_nanos", "currency", "pricing_lines", "key_id", "throughput"]

    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 GenerationResponse 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 usage
        if self.usage:
            _dict['usage'] = self.usage.to_dict()
        # set to None if app_id (nullable) is None
        # and model_fields_set contains the field
        if self.app_id is None and "app_id" in self.model_fields_set:
            _dict['app_id'] = None

        # set to None if native_response_id (nullable) is None
        # and model_fields_set contains the field
        if self.native_response_id is None and "native_response_id" in self.model_fields_set:
            _dict['native_response_id'] = None

        # set to None if error_code (nullable) is None
        # and model_fields_set contains the field
        if self.error_code is None and "error_code" in self.model_fields_set:
            _dict['error_code'] = None

        # set to None if error_message (nullable) is None
        # and model_fields_set contains the field
        if self.error_message is None and "error_message" in self.model_fields_set:
            _dict['error_message'] = None

        # set to None if usage (nullable) is None
        # and model_fields_set contains the field
        if self.usage is None and "usage" in self.model_fields_set:
            _dict['usage'] = None

        # set to None if throughput (nullable) is None
        # and model_fields_set contains the field
        if self.throughput is None and "throughput" in self.model_fields_set:
            _dict['throughput'] = None

        return _dict

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

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

        _obj = cls.model_validate({
            "request_id": obj.get("request_id"),
            "team_id": obj.get("team_id"),
            "app_id": obj.get("app_id"),
            "endpoint": obj.get("endpoint"),
            "model_id": obj.get("model_id"),
            "provider": obj.get("provider"),
            "native_response_id": obj.get("native_response_id"),
            "stream": obj.get("stream"),
            "byok": obj.get("byok"),
            "status_code": obj.get("status_code"),
            "success": obj.get("success"),
            "error_code": obj.get("error_code"),
            "error_message": obj.get("error_message"),
            "latency_ms": obj.get("latency_ms"),
            "generation_ms": obj.get("generation_ms"),
            "usage": GenerationResponseUsage.from_dict(obj["usage"]) if obj.get("usage") is not None else None,
            "cost_nanos": obj.get("cost_nanos"),
            "currency": obj.get("currency"),
            "pricing_lines": obj.get("pricing_lines"),
            "key_id": obj.get("key_id"),
            "throughput": obj.get("throughput")
        })
        return _obj


