# coding: utf-8

"""
    Rapidata Asset API

    The API for the Rapidata Asset service

    The version of the OpenAPI document: v1
    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 rapidata.api_client.models.i_metadata_model_classification_metadata_model import IMetadataModelClassificationMetadataModel
from rapidata.api_client.models.i_metadata_model_count_metadata_model import IMetadataModelCountMetadataModel
from rapidata.api_client.models.i_metadata_model_file_type_metadata_model import IMetadataModelFileTypeMetadataModel
from rapidata.api_client.models.i_metadata_model_image_dimension_metadata_model import IMetadataModelImageDimensionMetadataModel
from rapidata.api_client.models.i_metadata_model_location_metadata_model import IMetadataModelLocationMetadataModel
from rapidata.api_client.models.i_metadata_model_original_filename_metadata_model import IMetadataModelOriginalFilenameMetadataModel
from rapidata.api_client.models.i_metadata_model_source_url_metadata_model import IMetadataModelSourceUrlMetadataModel
from rapidata.api_client.models.i_metadata_model_streams_metadata_model import IMetadataModelStreamsMetadataModel
from rapidata.api_client.models.i_metadata_model_text_metadata_model import IMetadataModelTextMetadataModel
from rapidata.api_client.models.i_metadata_model_video_duration_metadata_model import IMetadataModelVideoDurationMetadataModel
from pydantic import StrictStr, Field
from typing import Union, List, Set, Optional, Dict
from typing_extensions import Literal, Self

IMETADATAMODEL_ONE_OF_SCHEMAS = ["IMetadataModelClassificationMetadataModel", "IMetadataModelCountMetadataModel", "IMetadataModelFileTypeMetadataModel", "IMetadataModelImageDimensionMetadataModel", "IMetadataModelLocationMetadataModel", "IMetadataModelOriginalFilenameMetadataModel", "IMetadataModelSourceUrlMetadataModel", "IMetadataModelStreamsMetadataModel", "IMetadataModelTextMetadataModel", "IMetadataModelVideoDurationMetadataModel"]

class IMetadataModel(BaseModel):
    """
    IMetadataModel
    """
    # data type: IMetadataModelClassificationMetadataModel
    oneof_schema_1_validator: Optional[IMetadataModelClassificationMetadataModel] = None
    # data type: IMetadataModelCountMetadataModel
    oneof_schema_2_validator: Optional[IMetadataModelCountMetadataModel] = None
    # data type: IMetadataModelFileTypeMetadataModel
    oneof_schema_3_validator: Optional[IMetadataModelFileTypeMetadataModel] = None
    # data type: IMetadataModelImageDimensionMetadataModel
    oneof_schema_4_validator: Optional[IMetadataModelImageDimensionMetadataModel] = None
    # data type: IMetadataModelLocationMetadataModel
    oneof_schema_5_validator: Optional[IMetadataModelLocationMetadataModel] = None
    # data type: IMetadataModelOriginalFilenameMetadataModel
    oneof_schema_6_validator: Optional[IMetadataModelOriginalFilenameMetadataModel] = None
    # data type: IMetadataModelSourceUrlMetadataModel
    oneof_schema_7_validator: Optional[IMetadataModelSourceUrlMetadataModel] = None
    # data type: IMetadataModelStreamsMetadataModel
    oneof_schema_8_validator: Optional[IMetadataModelStreamsMetadataModel] = None
    # data type: IMetadataModelTextMetadataModel
    oneof_schema_9_validator: Optional[IMetadataModelTextMetadataModel] = None
    # data type: IMetadataModelVideoDurationMetadataModel
    oneof_schema_10_validator: Optional[IMetadataModelVideoDurationMetadataModel] = None
    actual_instance: Optional[Union[IMetadataModelClassificationMetadataModel, IMetadataModelCountMetadataModel, IMetadataModelFileTypeMetadataModel, IMetadataModelImageDimensionMetadataModel, IMetadataModelLocationMetadataModel, IMetadataModelOriginalFilenameMetadataModel, IMetadataModelSourceUrlMetadataModel, IMetadataModelStreamsMetadataModel, IMetadataModelTextMetadataModel, IMetadataModelVideoDurationMetadataModel]] = None
    one_of_schemas: Set[str] = { "IMetadataModelClassificationMetadataModel", "IMetadataModelCountMetadataModel", "IMetadataModelFileTypeMetadataModel", "IMetadataModelImageDimensionMetadataModel", "IMetadataModelLocationMetadataModel", "IMetadataModelOriginalFilenameMetadataModel", "IMetadataModelSourceUrlMetadataModel", "IMetadataModelStreamsMetadataModel", "IMetadataModelTextMetadataModel", "IMetadataModelVideoDurationMetadataModel" }

    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 = IMetadataModel.model_construct()
        error_messages = []
        match = 0
        # validate data type: IMetadataModelClassificationMetadataModel
        if not isinstance(v, IMetadataModelClassificationMetadataModel):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IMetadataModelClassificationMetadataModel`")
        else:
            match += 1
        # validate data type: IMetadataModelCountMetadataModel
        if not isinstance(v, IMetadataModelCountMetadataModel):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IMetadataModelCountMetadataModel`")
        else:
            match += 1
        # validate data type: IMetadataModelFileTypeMetadataModel
        if not isinstance(v, IMetadataModelFileTypeMetadataModel):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IMetadataModelFileTypeMetadataModel`")
        else:
            match += 1
        # validate data type: IMetadataModelImageDimensionMetadataModel
        if not isinstance(v, IMetadataModelImageDimensionMetadataModel):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IMetadataModelImageDimensionMetadataModel`")
        else:
            match += 1
        # validate data type: IMetadataModelLocationMetadataModel
        if not isinstance(v, IMetadataModelLocationMetadataModel):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IMetadataModelLocationMetadataModel`")
        else:
            match += 1
        # validate data type: IMetadataModelOriginalFilenameMetadataModel
        if not isinstance(v, IMetadataModelOriginalFilenameMetadataModel):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IMetadataModelOriginalFilenameMetadataModel`")
        else:
            match += 1
        # validate data type: IMetadataModelSourceUrlMetadataModel
        if not isinstance(v, IMetadataModelSourceUrlMetadataModel):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IMetadataModelSourceUrlMetadataModel`")
        else:
            match += 1
        # validate data type: IMetadataModelStreamsMetadataModel
        if not isinstance(v, IMetadataModelStreamsMetadataModel):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IMetadataModelStreamsMetadataModel`")
        else:
            match += 1
        # validate data type: IMetadataModelTextMetadataModel
        if not isinstance(v, IMetadataModelTextMetadataModel):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IMetadataModelTextMetadataModel`")
        else:
            match += 1
        # validate data type: IMetadataModelVideoDurationMetadataModel
        if not isinstance(v, IMetadataModelVideoDurationMetadataModel):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IMetadataModelVideoDurationMetadataModel`")
        else:
            match += 1
        if match > 1:
            # more than 1 match
            raise ValueError("Multiple matches found when setting `actual_instance` in IMetadataModel with oneOf schemas: IMetadataModelClassificationMetadataModel, IMetadataModelCountMetadataModel, IMetadataModelFileTypeMetadataModel, IMetadataModelImageDimensionMetadataModel, IMetadataModelLocationMetadataModel, IMetadataModelOriginalFilenameMetadataModel, IMetadataModelSourceUrlMetadataModel, IMetadataModelStreamsMetadataModel, IMetadataModelTextMetadataModel, IMetadataModelVideoDurationMetadataModel. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when setting `actual_instance` in IMetadataModel with oneOf schemas: IMetadataModelClassificationMetadataModel, IMetadataModelCountMetadataModel, IMetadataModelFileTypeMetadataModel, IMetadataModelImageDimensionMetadataModel, IMetadataModelLocationMetadataModel, IMetadataModelOriginalFilenameMetadataModel, IMetadataModelSourceUrlMetadataModel, IMetadataModelStreamsMetadataModel, IMetadataModelTextMetadataModel, IMetadataModelVideoDurationMetadataModel. 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 IMetadataModelClassificationMetadataModel
        try:
            instance.actual_instance = IMetadataModelClassificationMetadataModel.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IMetadataModelCountMetadataModel
        try:
            instance.actual_instance = IMetadataModelCountMetadataModel.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IMetadataModelFileTypeMetadataModel
        try:
            instance.actual_instance = IMetadataModelFileTypeMetadataModel.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IMetadataModelImageDimensionMetadataModel
        try:
            instance.actual_instance = IMetadataModelImageDimensionMetadataModel.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IMetadataModelLocationMetadataModel
        try:
            instance.actual_instance = IMetadataModelLocationMetadataModel.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IMetadataModelOriginalFilenameMetadataModel
        try:
            instance.actual_instance = IMetadataModelOriginalFilenameMetadataModel.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IMetadataModelSourceUrlMetadataModel
        try:
            instance.actual_instance = IMetadataModelSourceUrlMetadataModel.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IMetadataModelStreamsMetadataModel
        try:
            instance.actual_instance = IMetadataModelStreamsMetadataModel.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IMetadataModelTextMetadataModel
        try:
            instance.actual_instance = IMetadataModelTextMetadataModel.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IMetadataModelVideoDurationMetadataModel
        try:
            instance.actual_instance = IMetadataModelVideoDurationMetadataModel.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 IMetadataModel with oneOf schemas: IMetadataModelClassificationMetadataModel, IMetadataModelCountMetadataModel, IMetadataModelFileTypeMetadataModel, IMetadataModelImageDimensionMetadataModel, IMetadataModelLocationMetadataModel, IMetadataModelOriginalFilenameMetadataModel, IMetadataModelSourceUrlMetadataModel, IMetadataModelStreamsMetadataModel, IMetadataModelTextMetadataModel, IMetadataModelVideoDurationMetadataModel. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when deserializing the JSON string into IMetadataModel with oneOf schemas: IMetadataModelClassificationMetadataModel, IMetadataModelCountMetadataModel, IMetadataModelFileTypeMetadataModel, IMetadataModelImageDimensionMetadataModel, IMetadataModelLocationMetadataModel, IMetadataModelOriginalFilenameMetadataModel, IMetadataModelSourceUrlMetadataModel, IMetadataModelStreamsMetadataModel, IMetadataModelTextMetadataModel, IMetadataModelVideoDurationMetadataModel. 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], IMetadataModelClassificationMetadataModel, IMetadataModelCountMetadataModel, IMetadataModelFileTypeMetadataModel, IMetadataModelImageDimensionMetadataModel, IMetadataModelLocationMetadataModel, IMetadataModelOriginalFilenameMetadataModel, IMetadataModelSourceUrlMetadataModel, IMetadataModelStreamsMetadataModel, IMetadataModelTextMetadataModel, IMetadataModelVideoDurationMetadataModel]]:
        """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())


