# coding: utf-8

"""
    AI Stats Gateway API

    Programmatic access to the AI Stats AI Gateway. All endpoints forward requests to the best available provider for the specified model, and return normalised responses with clear structured metadata.

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

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


from __future__ import annotations
import json
import pprint
from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator
from typing import Any, List, Optional
from ai_stats_generated.models.message_content_image_url import MessageContentImageUrl
from ai_stats_generated.models.message_content_input_audio import MessageContentInputAudio
from ai_stats_generated.models.message_content_input_video import MessageContentInputVideo
from ai_stats_generated.models.message_content_text import MessageContentText
from ai_stats_generated.models.tool_call_part import ToolCallPart
from pydantic import StrictStr, Field
from typing import Union, List, Set, Optional, Dict
from typing_extensions import Literal, Self

MESSAGECONTENTPART_ONE_OF_SCHEMAS = ["MessageContentImageUrl", "MessageContentInputAudio", "MessageContentInputVideo", "MessageContentText", "ToolCallPart"]

class MessageContentPart(BaseModel):
    """
    MessageContentPart
    """
    # data type: MessageContentText
    oneof_schema_1_validator: Optional[MessageContentText] = None
    # data type: MessageContentImageUrl
    oneof_schema_2_validator: Optional[MessageContentImageUrl] = None
    # data type: MessageContentInputAudio
    oneof_schema_3_validator: Optional[MessageContentInputAudio] = None
    # data type: MessageContentInputVideo
    oneof_schema_4_validator: Optional[MessageContentInputVideo] = None
    # data type: ToolCallPart
    oneof_schema_5_validator: Optional[ToolCallPart] = None
    actual_instance: Optional[Union[MessageContentImageUrl, MessageContentInputAudio, MessageContentInputVideo, MessageContentText, ToolCallPart]] = None
    one_of_schemas: Set[str] = { "MessageContentImageUrl", "MessageContentInputAudio", "MessageContentInputVideo", "MessageContentText", "ToolCallPart" }

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


    discriminator_value_class_map: Dict[str, str] = {
    }

    def __init__(self, *args, **kwargs) -> None:
        if args:
            if len(args) > 1:
                raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`")
            if kwargs:
                raise ValueError("If a position argument is used, keyword arguments cannot be used.")
            super().__init__(actual_instance=args[0])
        else:
            super().__init__(**kwargs)

    @field_validator('actual_instance')
    def actual_instance_must_validate_oneof(cls, v):
        instance = MessageContentPart.model_construct()
        error_messages = []
        match = 0
        # validate data type: MessageContentText
        if not isinstance(v, MessageContentText):
            error_messages.append(f"Error! Input type `{type(v)}` is not `MessageContentText`")
        else:
            match += 1
        # validate data type: MessageContentImageUrl
        if not isinstance(v, MessageContentImageUrl):
            error_messages.append(f"Error! Input type `{type(v)}` is not `MessageContentImageUrl`")
        else:
            match += 1
        # validate data type: MessageContentInputAudio
        if not isinstance(v, MessageContentInputAudio):
            error_messages.append(f"Error! Input type `{type(v)}` is not `MessageContentInputAudio`")
        else:
            match += 1
        # validate data type: MessageContentInputVideo
        if not isinstance(v, MessageContentInputVideo):
            error_messages.append(f"Error! Input type `{type(v)}` is not `MessageContentInputVideo`")
        else:
            match += 1
        # validate data type: ToolCallPart
        if not isinstance(v, ToolCallPart):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ToolCallPart`")
        else:
            match += 1
        if match > 1:
            # more than 1 match
            raise ValueError("Multiple matches found when setting `actual_instance` in MessageContentPart with oneOf schemas: MessageContentImageUrl, MessageContentInputAudio, MessageContentInputVideo, MessageContentText, ToolCallPart. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when setting `actual_instance` in MessageContentPart with oneOf schemas: MessageContentImageUrl, MessageContentInputAudio, MessageContentInputVideo, MessageContentText, ToolCallPart. Details: " + ", ".join(error_messages))
        else:
            return v

    @classmethod
    def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self:
        return cls.from_json(json.dumps(obj))

    @classmethod
    def from_json(cls, json_str: str) -> Self:
        """Returns the object represented by the json string"""
        instance = cls.model_construct()
        error_messages = []
        match = 0

        # deserialize data into MessageContentText
        try:
            instance.actual_instance = MessageContentText.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into MessageContentImageUrl
        try:
            instance.actual_instance = MessageContentImageUrl.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into MessageContentInputAudio
        try:
            instance.actual_instance = MessageContentInputAudio.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into MessageContentInputVideo
        try:
            instance.actual_instance = MessageContentInputVideo.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ToolCallPart
        try:
            instance.actual_instance = ToolCallPart.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))

        if match > 1:
            # more than 1 match
            raise ValueError("Multiple matches found when deserializing the JSON string into MessageContentPart with oneOf schemas: MessageContentImageUrl, MessageContentInputAudio, MessageContentInputVideo, MessageContentText, ToolCallPart. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when deserializing the JSON string into MessageContentPart with oneOf schemas: MessageContentImageUrl, MessageContentInputAudio, MessageContentInputVideo, MessageContentText, ToolCallPart. Details: " + ", ".join(error_messages))
        else:
            return instance

    def to_json(self) -> str:
        """Returns the JSON representation of the actual instance"""
        if self.actual_instance is None:
            return "null"

        if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json):
            return self.actual_instance.to_json()
        else:
            return json.dumps(self.actual_instance)

    def to_dict(self) -> Optional[Union[Dict[str, Any], MessageContentImageUrl, MessageContentInputAudio, MessageContentInputVideo, MessageContentText, ToolCallPart]]:
        """Returns the dict representation of the actual instance"""
        if self.actual_instance is None:
            return None

        if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict):
            return self.actual_instance.to_dict()
        else:
            # primitive type
            return self.actual_instance

    def to_str(self) -> str:
        """Returns the string representation of the actual instance"""
        return pprint.pformat(self.model_dump())


