# 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.attach_category_result import AttachCategoryResult
from rapidata.api_client.models.bounding_box_result import BoundingBoxResult
from rapidata.api_client.models.compare_result import CompareResult
from rapidata.api_client.models.free_text_result import FreeTextResult
from rapidata.api_client.models.line_result import LineResult
from rapidata.api_client.models.locate_result import LocateResult
from rapidata.api_client.models.named_entity_result import NamedEntityResult
from rapidata.api_client.models.polygon_result import PolygonResult
from rapidata.api_client.models.scrub_result import ScrubResult
from rapidata.api_client.models.skip_result import SkipResult
from rapidata.api_client.models.transcription_result import TranscriptionResult
from pydantic import StrictStr, Field
from typing import Union, List, Set, Optional, Dict
from typing_extensions import Literal, Self

GETRESPONSESFORRAPIDRESULTRESPONSERESULT_ONE_OF_SCHEMAS = ["AttachCategoryResult", "BoundingBoxResult", "CompareResult", "FreeTextResult", "LineResult", "LocateResult", "NamedEntityResult", "PolygonResult", "ScrubResult", "SkipResult", "TranscriptionResult"]

class GetResponsesForRapidResultResponseResult(BaseModel):
    """
    GetResponsesForRapidResultResponseResult
    """
    # data type: TranscriptionResult
    oneof_schema_1_validator: Optional[TranscriptionResult] = None
    # data type: ScrubResult
    oneof_schema_2_validator: Optional[ScrubResult] = None
    # data type: PolygonResult
    oneof_schema_3_validator: Optional[PolygonResult] = None
    # data type: NamedEntityResult
    oneof_schema_4_validator: Optional[NamedEntityResult] = None
    # data type: LocateResult
    oneof_schema_5_validator: Optional[LocateResult] = None
    # data type: LineResult
    oneof_schema_6_validator: Optional[LineResult] = None
    # data type: FreeTextResult
    oneof_schema_7_validator: Optional[FreeTextResult] = None
    # data type: CompareResult
    oneof_schema_8_validator: Optional[CompareResult] = None
    # data type: SkipResult
    oneof_schema_9_validator: Optional[SkipResult] = None
    # data type: AttachCategoryResult
    oneof_schema_10_validator: Optional[AttachCategoryResult] = None
    # data type: BoundingBoxResult
    oneof_schema_11_validator: Optional[BoundingBoxResult] = None
    actual_instance: Optional[Union[AttachCategoryResult, BoundingBoxResult, CompareResult, FreeTextResult, LineResult, LocateResult, NamedEntityResult, PolygonResult, ScrubResult, SkipResult, TranscriptionResult]] = None
    one_of_schemas: Set[str] = { "AttachCategoryResult", "BoundingBoxResult", "CompareResult", "FreeTextResult", "LineResult", "LocateResult", "NamedEntityResult", "PolygonResult", "ScrubResult", "SkipResult", "TranscriptionResult" }

    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 = GetResponsesForRapidResultResponseResult.model_construct()
        error_messages = []
        match = 0
        # validate data type: TranscriptionResult
        if not isinstance(v, TranscriptionResult):
            error_messages.append(f"Error! Input type `{type(v)}` is not `TranscriptionResult`")
        else:
            match += 1
        # validate data type: ScrubResult
        if not isinstance(v, ScrubResult):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ScrubResult`")
        else:
            match += 1
        # validate data type: PolygonResult
        if not isinstance(v, PolygonResult):
            error_messages.append(f"Error! Input type `{type(v)}` is not `PolygonResult`")
        else:
            match += 1
        # validate data type: NamedEntityResult
        if not isinstance(v, NamedEntityResult):
            error_messages.append(f"Error! Input type `{type(v)}` is not `NamedEntityResult`")
        else:
            match += 1
        # validate data type: LocateResult
        if not isinstance(v, LocateResult):
            error_messages.append(f"Error! Input type `{type(v)}` is not `LocateResult`")
        else:
            match += 1
        # validate data type: LineResult
        if not isinstance(v, LineResult):
            error_messages.append(f"Error! Input type `{type(v)}` is not `LineResult`")
        else:
            match += 1
        # validate data type: FreeTextResult
        if not isinstance(v, FreeTextResult):
            error_messages.append(f"Error! Input type `{type(v)}` is not `FreeTextResult`")
        else:
            match += 1
        # validate data type: CompareResult
        if not isinstance(v, CompareResult):
            error_messages.append(f"Error! Input type `{type(v)}` is not `CompareResult`")
        else:
            match += 1
        # validate data type: SkipResult
        if not isinstance(v, SkipResult):
            error_messages.append(f"Error! Input type `{type(v)}` is not `SkipResult`")
        else:
            match += 1
        # validate data type: AttachCategoryResult
        if not isinstance(v, AttachCategoryResult):
            error_messages.append(f"Error! Input type `{type(v)}` is not `AttachCategoryResult`")
        else:
            match += 1
        # validate data type: BoundingBoxResult
        if not isinstance(v, BoundingBoxResult):
            error_messages.append(f"Error! Input type `{type(v)}` is not `BoundingBoxResult`")
        else:
            match += 1
        if match > 1:
            # more than 1 match
            raise ValueError("Multiple matches found when setting `actual_instance` in GetResponsesForRapidResultResponseResult with oneOf schemas: AttachCategoryResult, BoundingBoxResult, CompareResult, FreeTextResult, LineResult, LocateResult, NamedEntityResult, PolygonResult, ScrubResult, SkipResult, TranscriptionResult. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when setting `actual_instance` in GetResponsesForRapidResultResponseResult with oneOf schemas: AttachCategoryResult, BoundingBoxResult, CompareResult, FreeTextResult, LineResult, LocateResult, NamedEntityResult, PolygonResult, ScrubResult, SkipResult, TranscriptionResult. 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 TranscriptionResult
        try:
            instance.actual_instance = TranscriptionResult.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ScrubResult
        try:
            instance.actual_instance = ScrubResult.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into PolygonResult
        try:
            instance.actual_instance = PolygonResult.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into NamedEntityResult
        try:
            instance.actual_instance = NamedEntityResult.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into LocateResult
        try:
            instance.actual_instance = LocateResult.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into LineResult
        try:
            instance.actual_instance = LineResult.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into FreeTextResult
        try:
            instance.actual_instance = FreeTextResult.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into CompareResult
        try:
            instance.actual_instance = CompareResult.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into SkipResult
        try:
            instance.actual_instance = SkipResult.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into AttachCategoryResult
        try:
            instance.actual_instance = AttachCategoryResult.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into BoundingBoxResult
        try:
            instance.actual_instance = BoundingBoxResult.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 GetResponsesForRapidResultResponseResult with oneOf schemas: AttachCategoryResult, BoundingBoxResult, CompareResult, FreeTextResult, LineResult, LocateResult, NamedEntityResult, PolygonResult, ScrubResult, SkipResult, TranscriptionResult. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when deserializing the JSON string into GetResponsesForRapidResultResponseResult with oneOf schemas: AttachCategoryResult, BoundingBoxResult, CompareResult, FreeTextResult, LineResult, LocateResult, NamedEntityResult, PolygonResult, ScrubResult, SkipResult, TranscriptionResult. 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], AttachCategoryResult, BoundingBoxResult, CompareResult, FreeTextResult, LineResult, LocateResult, NamedEntityResult, PolygonResult, ScrubResult, SkipResult, TranscriptionResult]]:
        """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())


