# 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_rapid_result_attach_category_result import IRapidResultAttachCategoryResult
from rapidata.api_client.models.i_rapid_result_bounding_box_result import IRapidResultBoundingBoxResult
from rapidata.api_client.models.i_rapid_result_compare_result import IRapidResultCompareResult
from rapidata.api_client.models.i_rapid_result_free_text_result import IRapidResultFreeTextResult
from rapidata.api_client.models.i_rapid_result_line_result import IRapidResultLineResult
from rapidata.api_client.models.i_rapid_result_locate_result import IRapidResultLocateResult
from rapidata.api_client.models.i_rapid_result_named_entity_result import IRapidResultNamedEntityResult
from rapidata.api_client.models.i_rapid_result_polygon_result import IRapidResultPolygonResult
from rapidata.api_client.models.i_rapid_result_scrub_result import IRapidResultScrubResult
from rapidata.api_client.models.i_rapid_result_skip_result import IRapidResultSkipResult
from rapidata.api_client.models.i_rapid_result_transcription_result import IRapidResultTranscriptionResult
from pydantic import StrictStr, Field
from typing import Union, List, Set, Optional, Dict
from typing_extensions import Literal, Self

IRAPIDRESULT_ONE_OF_SCHEMAS = ["IRapidResultAttachCategoryResult", "IRapidResultBoundingBoxResult", "IRapidResultCompareResult", "IRapidResultFreeTextResult", "IRapidResultLineResult", "IRapidResultLocateResult", "IRapidResultNamedEntityResult", "IRapidResultPolygonResult", "IRapidResultScrubResult", "IRapidResultSkipResult", "IRapidResultTranscriptionResult"]

class IRapidResult(BaseModel):
    """
    IRapidResult
    """
    # data type: IRapidResultTranscriptionResult
    oneof_schema_1_validator: Optional[IRapidResultTranscriptionResult] = None
    # data type: IRapidResultScrubResult
    oneof_schema_2_validator: Optional[IRapidResultScrubResult] = None
    # data type: IRapidResultPolygonResult
    oneof_schema_3_validator: Optional[IRapidResultPolygonResult] = None
    # data type: IRapidResultNamedEntityResult
    oneof_schema_4_validator: Optional[IRapidResultNamedEntityResult] = None
    # data type: IRapidResultLocateResult
    oneof_schema_5_validator: Optional[IRapidResultLocateResult] = None
    # data type: IRapidResultLineResult
    oneof_schema_6_validator: Optional[IRapidResultLineResult] = None
    # data type: IRapidResultFreeTextResult
    oneof_schema_7_validator: Optional[IRapidResultFreeTextResult] = None
    # data type: IRapidResultCompareResult
    oneof_schema_8_validator: Optional[IRapidResultCompareResult] = None
    # data type: IRapidResultSkipResult
    oneof_schema_9_validator: Optional[IRapidResultSkipResult] = None
    # data type: IRapidResultAttachCategoryResult
    oneof_schema_10_validator: Optional[IRapidResultAttachCategoryResult] = None
    # data type: IRapidResultBoundingBoxResult
    oneof_schema_11_validator: Optional[IRapidResultBoundingBoxResult] = None
    actual_instance: Optional[Union[IRapidResultAttachCategoryResult, IRapidResultBoundingBoxResult, IRapidResultCompareResult, IRapidResultFreeTextResult, IRapidResultLineResult, IRapidResultLocateResult, IRapidResultNamedEntityResult, IRapidResultPolygonResult, IRapidResultScrubResult, IRapidResultSkipResult, IRapidResultTranscriptionResult]] = None
    one_of_schemas: Set[str] = { "IRapidResultAttachCategoryResult", "IRapidResultBoundingBoxResult", "IRapidResultCompareResult", "IRapidResultFreeTextResult", "IRapidResultLineResult", "IRapidResultLocateResult", "IRapidResultNamedEntityResult", "IRapidResultPolygonResult", "IRapidResultScrubResult", "IRapidResultSkipResult", "IRapidResultTranscriptionResult" }

    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 = IRapidResult.model_construct()
        error_messages = []
        match = 0
        # validate data type: IRapidResultTranscriptionResult
        if not isinstance(v, IRapidResultTranscriptionResult):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IRapidResultTranscriptionResult`")
        else:
            match += 1
        # validate data type: IRapidResultScrubResult
        if not isinstance(v, IRapidResultScrubResult):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IRapidResultScrubResult`")
        else:
            match += 1
        # validate data type: IRapidResultPolygonResult
        if not isinstance(v, IRapidResultPolygonResult):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IRapidResultPolygonResult`")
        else:
            match += 1
        # validate data type: IRapidResultNamedEntityResult
        if not isinstance(v, IRapidResultNamedEntityResult):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IRapidResultNamedEntityResult`")
        else:
            match += 1
        # validate data type: IRapidResultLocateResult
        if not isinstance(v, IRapidResultLocateResult):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IRapidResultLocateResult`")
        else:
            match += 1
        # validate data type: IRapidResultLineResult
        if not isinstance(v, IRapidResultLineResult):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IRapidResultLineResult`")
        else:
            match += 1
        # validate data type: IRapidResultFreeTextResult
        if not isinstance(v, IRapidResultFreeTextResult):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IRapidResultFreeTextResult`")
        else:
            match += 1
        # validate data type: IRapidResultCompareResult
        if not isinstance(v, IRapidResultCompareResult):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IRapidResultCompareResult`")
        else:
            match += 1
        # validate data type: IRapidResultSkipResult
        if not isinstance(v, IRapidResultSkipResult):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IRapidResultSkipResult`")
        else:
            match += 1
        # validate data type: IRapidResultAttachCategoryResult
        if not isinstance(v, IRapidResultAttachCategoryResult):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IRapidResultAttachCategoryResult`")
        else:
            match += 1
        # validate data type: IRapidResultBoundingBoxResult
        if not isinstance(v, IRapidResultBoundingBoxResult):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IRapidResultBoundingBoxResult`")
        else:
            match += 1
        if match > 1:
            # more than 1 match
            raise ValueError("Multiple matches found when setting `actual_instance` in IRapidResult with oneOf schemas: IRapidResultAttachCategoryResult, IRapidResultBoundingBoxResult, IRapidResultCompareResult, IRapidResultFreeTextResult, IRapidResultLineResult, IRapidResultLocateResult, IRapidResultNamedEntityResult, IRapidResultPolygonResult, IRapidResultScrubResult, IRapidResultSkipResult, IRapidResultTranscriptionResult. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when setting `actual_instance` in IRapidResult with oneOf schemas: IRapidResultAttachCategoryResult, IRapidResultBoundingBoxResult, IRapidResultCompareResult, IRapidResultFreeTextResult, IRapidResultLineResult, IRapidResultLocateResult, IRapidResultNamedEntityResult, IRapidResultPolygonResult, IRapidResultScrubResult, IRapidResultSkipResult, IRapidResultTranscriptionResult. 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 IRapidResultTranscriptionResult
        try:
            instance.actual_instance = IRapidResultTranscriptionResult.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IRapidResultScrubResult
        try:
            instance.actual_instance = IRapidResultScrubResult.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IRapidResultPolygonResult
        try:
            instance.actual_instance = IRapidResultPolygonResult.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IRapidResultNamedEntityResult
        try:
            instance.actual_instance = IRapidResultNamedEntityResult.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IRapidResultLocateResult
        try:
            instance.actual_instance = IRapidResultLocateResult.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IRapidResultLineResult
        try:
            instance.actual_instance = IRapidResultLineResult.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IRapidResultFreeTextResult
        try:
            instance.actual_instance = IRapidResultFreeTextResult.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IRapidResultCompareResult
        try:
            instance.actual_instance = IRapidResultCompareResult.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IRapidResultSkipResult
        try:
            instance.actual_instance = IRapidResultSkipResult.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IRapidResultAttachCategoryResult
        try:
            instance.actual_instance = IRapidResultAttachCategoryResult.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IRapidResultBoundingBoxResult
        try:
            instance.actual_instance = IRapidResultBoundingBoxResult.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 IRapidResult with oneOf schemas: IRapidResultAttachCategoryResult, IRapidResultBoundingBoxResult, IRapidResultCompareResult, IRapidResultFreeTextResult, IRapidResultLineResult, IRapidResultLocateResult, IRapidResultNamedEntityResult, IRapidResultPolygonResult, IRapidResultScrubResult, IRapidResultSkipResult, IRapidResultTranscriptionResult. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when deserializing the JSON string into IRapidResult with oneOf schemas: IRapidResultAttachCategoryResult, IRapidResultBoundingBoxResult, IRapidResultCompareResult, IRapidResultFreeTextResult, IRapidResultLineResult, IRapidResultLocateResult, IRapidResultNamedEntityResult, IRapidResultPolygonResult, IRapidResultScrubResult, IRapidResultSkipResult, IRapidResultTranscriptionResult. 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], IRapidResultAttachCategoryResult, IRapidResultBoundingBoxResult, IRapidResultCompareResult, IRapidResultFreeTextResult, IRapidResultLineResult, IRapidResultLocateResult, IRapidResultNamedEntityResult, IRapidResultPolygonResult, IRapidResultScrubResult, IRapidResultSkipResult, IRapidResultTranscriptionResult]]:
        """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())


