# 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_classification_metadata import IMetadataClassificationMetadata
from rapidata.api_client.models.i_metadata_count_metadata import IMetadataCountMetadata
from rapidata.api_client.models.i_metadata_file_type_metadata import IMetadataFileTypeMetadata
from rapidata.api_client.models.i_metadata_image_dimension_metadata import IMetadataImageDimensionMetadata
from rapidata.api_client.models.i_metadata_location_metadata import IMetadataLocationMetadata
from rapidata.api_client.models.i_metadata_original_filename_metadata import IMetadataOriginalFilenameMetadata
from rapidata.api_client.models.i_metadata_source_url_metadata import IMetadataSourceUrlMetadata
from rapidata.api_client.models.i_metadata_streams_metadata import IMetadataStreamsMetadata
from rapidata.api_client.models.i_metadata_text_metadata import IMetadataTextMetadata
from rapidata.api_client.models.i_metadata_video_duration_metadata import IMetadataVideoDurationMetadata
from pydantic import StrictStr, Field
from typing import Union, List, Set, Optional, Dict
from typing_extensions import Literal, Self

IMETADATA_ONE_OF_SCHEMAS = ["IMetadataClassificationMetadata", "IMetadataCountMetadata", "IMetadataFileTypeMetadata", "IMetadataImageDimensionMetadata", "IMetadataLocationMetadata", "IMetadataOriginalFilenameMetadata", "IMetadataSourceUrlMetadata", "IMetadataStreamsMetadata", "IMetadataTextMetadata", "IMetadataVideoDurationMetadata"]

class IMetadata(BaseModel):
    """
    IMetadata
    """
    # data type: IMetadataClassificationMetadata
    oneof_schema_1_validator: Optional[IMetadataClassificationMetadata] = None
    # data type: IMetadataCountMetadata
    oneof_schema_2_validator: Optional[IMetadataCountMetadata] = None
    # data type: IMetadataFileTypeMetadata
    oneof_schema_3_validator: Optional[IMetadataFileTypeMetadata] = None
    # data type: IMetadataImageDimensionMetadata
    oneof_schema_4_validator: Optional[IMetadataImageDimensionMetadata] = None
    # data type: IMetadataLocationMetadata
    oneof_schema_5_validator: Optional[IMetadataLocationMetadata] = None
    # data type: IMetadataOriginalFilenameMetadata
    oneof_schema_6_validator: Optional[IMetadataOriginalFilenameMetadata] = None
    # data type: IMetadataSourceUrlMetadata
    oneof_schema_7_validator: Optional[IMetadataSourceUrlMetadata] = None
    # data type: IMetadataStreamsMetadata
    oneof_schema_8_validator: Optional[IMetadataStreamsMetadata] = None
    # data type: IMetadataTextMetadata
    oneof_schema_9_validator: Optional[IMetadataTextMetadata] = None
    # data type: IMetadataVideoDurationMetadata
    oneof_schema_10_validator: Optional[IMetadataVideoDurationMetadata] = None
    actual_instance: Optional[Union[IMetadataClassificationMetadata, IMetadataCountMetadata, IMetadataFileTypeMetadata, IMetadataImageDimensionMetadata, IMetadataLocationMetadata, IMetadataOriginalFilenameMetadata, IMetadataSourceUrlMetadata, IMetadataStreamsMetadata, IMetadataTextMetadata, IMetadataVideoDurationMetadata]] = None
    one_of_schemas: Set[str] = { "IMetadataClassificationMetadata", "IMetadataCountMetadata", "IMetadataFileTypeMetadata", "IMetadataImageDimensionMetadata", "IMetadataLocationMetadata", "IMetadataOriginalFilenameMetadata", "IMetadataSourceUrlMetadata", "IMetadataStreamsMetadata", "IMetadataTextMetadata", "IMetadataVideoDurationMetadata" }

    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 = IMetadata.model_construct()
        error_messages = []
        match = 0
        # validate data type: IMetadataClassificationMetadata
        if not isinstance(v, IMetadataClassificationMetadata):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IMetadataClassificationMetadata`")
        else:
            match += 1
        # validate data type: IMetadataCountMetadata
        if not isinstance(v, IMetadataCountMetadata):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IMetadataCountMetadata`")
        else:
            match += 1
        # validate data type: IMetadataFileTypeMetadata
        if not isinstance(v, IMetadataFileTypeMetadata):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IMetadataFileTypeMetadata`")
        else:
            match += 1
        # validate data type: IMetadataImageDimensionMetadata
        if not isinstance(v, IMetadataImageDimensionMetadata):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IMetadataImageDimensionMetadata`")
        else:
            match += 1
        # validate data type: IMetadataLocationMetadata
        if not isinstance(v, IMetadataLocationMetadata):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IMetadataLocationMetadata`")
        else:
            match += 1
        # validate data type: IMetadataOriginalFilenameMetadata
        if not isinstance(v, IMetadataOriginalFilenameMetadata):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IMetadataOriginalFilenameMetadata`")
        else:
            match += 1
        # validate data type: IMetadataSourceUrlMetadata
        if not isinstance(v, IMetadataSourceUrlMetadata):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IMetadataSourceUrlMetadata`")
        else:
            match += 1
        # validate data type: IMetadataStreamsMetadata
        if not isinstance(v, IMetadataStreamsMetadata):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IMetadataStreamsMetadata`")
        else:
            match += 1
        # validate data type: IMetadataTextMetadata
        if not isinstance(v, IMetadataTextMetadata):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IMetadataTextMetadata`")
        else:
            match += 1
        # validate data type: IMetadataVideoDurationMetadata
        if not isinstance(v, IMetadataVideoDurationMetadata):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IMetadataVideoDurationMetadata`")
        else:
            match += 1
        if match > 1:
            # more than 1 match
            raise ValueError("Multiple matches found when setting `actual_instance` in IMetadata with oneOf schemas: IMetadataClassificationMetadata, IMetadataCountMetadata, IMetadataFileTypeMetadata, IMetadataImageDimensionMetadata, IMetadataLocationMetadata, IMetadataOriginalFilenameMetadata, IMetadataSourceUrlMetadata, IMetadataStreamsMetadata, IMetadataTextMetadata, IMetadataVideoDurationMetadata. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when setting `actual_instance` in IMetadata with oneOf schemas: IMetadataClassificationMetadata, IMetadataCountMetadata, IMetadataFileTypeMetadata, IMetadataImageDimensionMetadata, IMetadataLocationMetadata, IMetadataOriginalFilenameMetadata, IMetadataSourceUrlMetadata, IMetadataStreamsMetadata, IMetadataTextMetadata, IMetadataVideoDurationMetadata. 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 IMetadataClassificationMetadata
        try:
            instance.actual_instance = IMetadataClassificationMetadata.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IMetadataCountMetadata
        try:
            instance.actual_instance = IMetadataCountMetadata.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IMetadataFileTypeMetadata
        try:
            instance.actual_instance = IMetadataFileTypeMetadata.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IMetadataImageDimensionMetadata
        try:
            instance.actual_instance = IMetadataImageDimensionMetadata.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IMetadataLocationMetadata
        try:
            instance.actual_instance = IMetadataLocationMetadata.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IMetadataOriginalFilenameMetadata
        try:
            instance.actual_instance = IMetadataOriginalFilenameMetadata.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IMetadataSourceUrlMetadata
        try:
            instance.actual_instance = IMetadataSourceUrlMetadata.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IMetadataStreamsMetadata
        try:
            instance.actual_instance = IMetadataStreamsMetadata.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IMetadataTextMetadata
        try:
            instance.actual_instance = IMetadataTextMetadata.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IMetadataVideoDurationMetadata
        try:
            instance.actual_instance = IMetadataVideoDurationMetadata.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 IMetadata with oneOf schemas: IMetadataClassificationMetadata, IMetadataCountMetadata, IMetadataFileTypeMetadata, IMetadataImageDimensionMetadata, IMetadataLocationMetadata, IMetadataOriginalFilenameMetadata, IMetadataSourceUrlMetadata, IMetadataStreamsMetadata, IMetadataTextMetadata, IMetadataVideoDurationMetadata. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when deserializing the JSON string into IMetadata with oneOf schemas: IMetadataClassificationMetadata, IMetadataCountMetadata, IMetadataFileTypeMetadata, IMetadataImageDimensionMetadata, IMetadataLocationMetadata, IMetadataOriginalFilenameMetadata, IMetadataSourceUrlMetadata, IMetadataStreamsMetadata, IMetadataTextMetadata, IMetadataVideoDurationMetadata. 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], IMetadataClassificationMetadata, IMetadataCountMetadata, IMetadataFileTypeMetadata, IMetadataImageDimensionMetadata, IMetadataLocationMetadata, IMetadataOriginalFilenameMetadata, IMetadataSourceUrlMetadata, IMetadataStreamsMetadata, IMetadataTextMetadata, IMetadataVideoDurationMetadata]]:
        """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())


