# coding: utf-8

"""
    Rapidata.Dataset

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    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.classification_metadata import ClassificationMetadata
from rapidata.api_client.models.count_metadata import CountMetadata
from rapidata.api_client.models.file_type_metadata import FileTypeMetadata
from rapidata.api_client.models.image_dimension_metadata import ImageDimensionMetadata
from rapidata.api_client.models.location_metadata import LocationMetadata
from rapidata.api_client.models.original_filename_metadata import OriginalFilenameMetadata
from rapidata.api_client.models.source_url_metadata import SourceUrlMetadata
from rapidata.api_client.models.streams_metadata import StreamsMetadata
from rapidata.api_client.models.text_metadata import TextMetadata
from rapidata.api_client.models.video_duration_metadata import VideoDurationMetadata
from pydantic import StrictStr, Field
from typing import Union, List, Set, Optional, Dict
from typing_extensions import Literal, Self

FILEASSETMETADATAVALUE_ONE_OF_SCHEMAS = ["ClassificationMetadata", "CountMetadata", "FileTypeMetadata", "ImageDimensionMetadata", "LocationMetadata", "OriginalFilenameMetadata", "SourceUrlMetadata", "StreamsMetadata", "TextMetadata", "VideoDurationMetadata"]

class FileAssetMetadataValue(BaseModel):
    """
    FileAssetMetadataValue
    """
    # data type: ClassificationMetadata
    oneof_schema_1_validator: Optional[ClassificationMetadata] = None
    # data type: CountMetadata
    oneof_schema_2_validator: Optional[CountMetadata] = None
    # data type: FileTypeMetadata
    oneof_schema_3_validator: Optional[FileTypeMetadata] = None
    # data type: ImageDimensionMetadata
    oneof_schema_4_validator: Optional[ImageDimensionMetadata] = None
    # data type: LocationMetadata
    oneof_schema_5_validator: Optional[LocationMetadata] = None
    # data type: OriginalFilenameMetadata
    oneof_schema_6_validator: Optional[OriginalFilenameMetadata] = None
    # data type: SourceUrlMetadata
    oneof_schema_7_validator: Optional[SourceUrlMetadata] = None
    # data type: StreamsMetadata
    oneof_schema_8_validator: Optional[StreamsMetadata] = None
    # data type: TextMetadata
    oneof_schema_9_validator: Optional[TextMetadata] = None
    # data type: VideoDurationMetadata
    oneof_schema_10_validator: Optional[VideoDurationMetadata] = None
    actual_instance: Optional[Union[ClassificationMetadata, CountMetadata, FileTypeMetadata, ImageDimensionMetadata, LocationMetadata, OriginalFilenameMetadata, SourceUrlMetadata, StreamsMetadata, TextMetadata, VideoDurationMetadata]] = None
    one_of_schemas: Set[str] = { "ClassificationMetadata", "CountMetadata", "FileTypeMetadata", "ImageDimensionMetadata", "LocationMetadata", "OriginalFilenameMetadata", "SourceUrlMetadata", "StreamsMetadata", "TextMetadata", "VideoDurationMetadata" }

    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 = FileAssetMetadataValue.model_construct()
        error_messages = []
        match = 0
        # validate data type: ClassificationMetadata
        if not isinstance(v, ClassificationMetadata):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ClassificationMetadata`")
        else:
            match += 1
        # validate data type: CountMetadata
        if not isinstance(v, CountMetadata):
            error_messages.append(f"Error! Input type `{type(v)}` is not `CountMetadata`")
        else:
            match += 1
        # validate data type: FileTypeMetadata
        if not isinstance(v, FileTypeMetadata):
            error_messages.append(f"Error! Input type `{type(v)}` is not `FileTypeMetadata`")
        else:
            match += 1
        # validate data type: ImageDimensionMetadata
        if not isinstance(v, ImageDimensionMetadata):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ImageDimensionMetadata`")
        else:
            match += 1
        # validate data type: LocationMetadata
        if not isinstance(v, LocationMetadata):
            error_messages.append(f"Error! Input type `{type(v)}` is not `LocationMetadata`")
        else:
            match += 1
        # validate data type: OriginalFilenameMetadata
        if not isinstance(v, OriginalFilenameMetadata):
            error_messages.append(f"Error! Input type `{type(v)}` is not `OriginalFilenameMetadata`")
        else:
            match += 1
        # validate data type: SourceUrlMetadata
        if not isinstance(v, SourceUrlMetadata):
            error_messages.append(f"Error! Input type `{type(v)}` is not `SourceUrlMetadata`")
        else:
            match += 1
        # validate data type: StreamsMetadata
        if not isinstance(v, StreamsMetadata):
            error_messages.append(f"Error! Input type `{type(v)}` is not `StreamsMetadata`")
        else:
            match += 1
        # validate data type: TextMetadata
        if not isinstance(v, TextMetadata):
            error_messages.append(f"Error! Input type `{type(v)}` is not `TextMetadata`")
        else:
            match += 1
        # validate data type: VideoDurationMetadata
        if not isinstance(v, VideoDurationMetadata):
            error_messages.append(f"Error! Input type `{type(v)}` is not `VideoDurationMetadata`")
        else:
            match += 1
        if match > 1:
            # more than 1 match
            raise ValueError("Multiple matches found when setting `actual_instance` in FileAssetMetadataValue with oneOf schemas: ClassificationMetadata, CountMetadata, FileTypeMetadata, ImageDimensionMetadata, LocationMetadata, OriginalFilenameMetadata, SourceUrlMetadata, StreamsMetadata, TextMetadata, VideoDurationMetadata. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when setting `actual_instance` in FileAssetMetadataValue with oneOf schemas: ClassificationMetadata, CountMetadata, FileTypeMetadata, ImageDimensionMetadata, LocationMetadata, OriginalFilenameMetadata, SourceUrlMetadata, StreamsMetadata, TextMetadata, VideoDurationMetadata. 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 ClassificationMetadata
        try:
            instance.actual_instance = ClassificationMetadata.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into CountMetadata
        try:
            instance.actual_instance = CountMetadata.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into FileTypeMetadata
        try:
            instance.actual_instance = FileTypeMetadata.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ImageDimensionMetadata
        try:
            instance.actual_instance = ImageDimensionMetadata.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into LocationMetadata
        try:
            instance.actual_instance = LocationMetadata.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into OriginalFilenameMetadata
        try:
            instance.actual_instance = OriginalFilenameMetadata.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into SourceUrlMetadata
        try:
            instance.actual_instance = SourceUrlMetadata.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into StreamsMetadata
        try:
            instance.actual_instance = StreamsMetadata.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into TextMetadata
        try:
            instance.actual_instance = TextMetadata.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into VideoDurationMetadata
        try:
            instance.actual_instance = VideoDurationMetadata.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 FileAssetMetadataValue with oneOf schemas: ClassificationMetadata, CountMetadata, FileTypeMetadata, ImageDimensionMetadata, LocationMetadata, OriginalFilenameMetadata, SourceUrlMetadata, StreamsMetadata, TextMetadata, VideoDurationMetadata. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when deserializing the JSON string into FileAssetMetadataValue with oneOf schemas: ClassificationMetadata, CountMetadata, FileTypeMetadata, ImageDimensionMetadata, LocationMetadata, OriginalFilenameMetadata, SourceUrlMetadata, StreamsMetadata, TextMetadata, VideoDurationMetadata. 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], ClassificationMetadata, CountMetadata, FileTypeMetadata, ImageDimensionMetadata, LocationMetadata, OriginalFilenameMetadata, SourceUrlMetadata, StreamsMetadata, TextMetadata, VideoDurationMetadata]]:
        """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())


