# 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_payload_bounding_box_payload import IRapidPayloadBoundingBoxPayload
from rapidata.api_client.models.i_rapid_payload_classify_payload import IRapidPayloadClassifyPayload
from rapidata.api_client.models.i_rapid_payload_compare_payload import IRapidPayloadComparePayload
from rapidata.api_client.models.i_rapid_payload_free_text_payload import IRapidPayloadFreeTextPayload
from rapidata.api_client.models.i_rapid_payload_line_payload import IRapidPayloadLinePayload
from rapidata.api_client.models.i_rapid_payload_locate_payload import IRapidPayloadLocatePayload
from rapidata.api_client.models.i_rapid_payload_named_entity_payload import IRapidPayloadNamedEntityPayload
from rapidata.api_client.models.i_rapid_payload_polygon_payload import IRapidPayloadPolygonPayload
from rapidata.api_client.models.i_rapid_payload_scrub_payload import IRapidPayloadScrubPayload
from rapidata.api_client.models.i_rapid_payload_transcription_payload import IRapidPayloadTranscriptionPayload
from pydantic import StrictStr, Field
from typing import Union, List, Set, Optional, Dict
from typing_extensions import Literal, Self

IRAPIDPAYLOAD_ONE_OF_SCHEMAS = ["IRapidPayloadBoundingBoxPayload", "IRapidPayloadClassifyPayload", "IRapidPayloadComparePayload", "IRapidPayloadFreeTextPayload", "IRapidPayloadLinePayload", "IRapidPayloadLocatePayload", "IRapidPayloadNamedEntityPayload", "IRapidPayloadPolygonPayload", "IRapidPayloadScrubPayload", "IRapidPayloadTranscriptionPayload"]

class IRapidPayload(BaseModel):
    """
    IRapidPayload
    """
    # data type: IRapidPayloadTranscriptionPayload
    oneof_schema_1_validator: Optional[IRapidPayloadTranscriptionPayload] = None
    # data type: IRapidPayloadScrubPayload
    oneof_schema_2_validator: Optional[IRapidPayloadScrubPayload] = None
    # data type: IRapidPayloadPolygonPayload
    oneof_schema_3_validator: Optional[IRapidPayloadPolygonPayload] = None
    # data type: IRapidPayloadNamedEntityPayload
    oneof_schema_4_validator: Optional[IRapidPayloadNamedEntityPayload] = None
    # data type: IRapidPayloadLocatePayload
    oneof_schema_5_validator: Optional[IRapidPayloadLocatePayload] = None
    # data type: IRapidPayloadLinePayload
    oneof_schema_6_validator: Optional[IRapidPayloadLinePayload] = None
    # data type: IRapidPayloadFreeTextPayload
    oneof_schema_7_validator: Optional[IRapidPayloadFreeTextPayload] = None
    # data type: IRapidPayloadComparePayload
    oneof_schema_8_validator: Optional[IRapidPayloadComparePayload] = None
    # data type: IRapidPayloadClassifyPayload
    oneof_schema_9_validator: Optional[IRapidPayloadClassifyPayload] = None
    # data type: IRapidPayloadBoundingBoxPayload
    oneof_schema_10_validator: Optional[IRapidPayloadBoundingBoxPayload] = None
    actual_instance: Optional[Union[IRapidPayloadBoundingBoxPayload, IRapidPayloadClassifyPayload, IRapidPayloadComparePayload, IRapidPayloadFreeTextPayload, IRapidPayloadLinePayload, IRapidPayloadLocatePayload, IRapidPayloadNamedEntityPayload, IRapidPayloadPolygonPayload, IRapidPayloadScrubPayload, IRapidPayloadTranscriptionPayload]] = None
    one_of_schemas: Set[str] = { "IRapidPayloadBoundingBoxPayload", "IRapidPayloadClassifyPayload", "IRapidPayloadComparePayload", "IRapidPayloadFreeTextPayload", "IRapidPayloadLinePayload", "IRapidPayloadLocatePayload", "IRapidPayloadNamedEntityPayload", "IRapidPayloadPolygonPayload", "IRapidPayloadScrubPayload", "IRapidPayloadTranscriptionPayload" }

    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 = IRapidPayload.model_construct()
        error_messages = []
        match = 0
        # validate data type: IRapidPayloadTranscriptionPayload
        if not isinstance(v, IRapidPayloadTranscriptionPayload):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IRapidPayloadTranscriptionPayload`")
        else:
            match += 1
        # validate data type: IRapidPayloadScrubPayload
        if not isinstance(v, IRapidPayloadScrubPayload):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IRapidPayloadScrubPayload`")
        else:
            match += 1
        # validate data type: IRapidPayloadPolygonPayload
        if not isinstance(v, IRapidPayloadPolygonPayload):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IRapidPayloadPolygonPayload`")
        else:
            match += 1
        # validate data type: IRapidPayloadNamedEntityPayload
        if not isinstance(v, IRapidPayloadNamedEntityPayload):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IRapidPayloadNamedEntityPayload`")
        else:
            match += 1
        # validate data type: IRapidPayloadLocatePayload
        if not isinstance(v, IRapidPayloadLocatePayload):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IRapidPayloadLocatePayload`")
        else:
            match += 1
        # validate data type: IRapidPayloadLinePayload
        if not isinstance(v, IRapidPayloadLinePayload):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IRapidPayloadLinePayload`")
        else:
            match += 1
        # validate data type: IRapidPayloadFreeTextPayload
        if not isinstance(v, IRapidPayloadFreeTextPayload):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IRapidPayloadFreeTextPayload`")
        else:
            match += 1
        # validate data type: IRapidPayloadComparePayload
        if not isinstance(v, IRapidPayloadComparePayload):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IRapidPayloadComparePayload`")
        else:
            match += 1
        # validate data type: IRapidPayloadClassifyPayload
        if not isinstance(v, IRapidPayloadClassifyPayload):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IRapidPayloadClassifyPayload`")
        else:
            match += 1
        # validate data type: IRapidPayloadBoundingBoxPayload
        if not isinstance(v, IRapidPayloadBoundingBoxPayload):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IRapidPayloadBoundingBoxPayload`")
        else:
            match += 1
        if match > 1:
            # more than 1 match
            raise ValueError("Multiple matches found when setting `actual_instance` in IRapidPayload with oneOf schemas: IRapidPayloadBoundingBoxPayload, IRapidPayloadClassifyPayload, IRapidPayloadComparePayload, IRapidPayloadFreeTextPayload, IRapidPayloadLinePayload, IRapidPayloadLocatePayload, IRapidPayloadNamedEntityPayload, IRapidPayloadPolygonPayload, IRapidPayloadScrubPayload, IRapidPayloadTranscriptionPayload. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when setting `actual_instance` in IRapidPayload with oneOf schemas: IRapidPayloadBoundingBoxPayload, IRapidPayloadClassifyPayload, IRapidPayloadComparePayload, IRapidPayloadFreeTextPayload, IRapidPayloadLinePayload, IRapidPayloadLocatePayload, IRapidPayloadNamedEntityPayload, IRapidPayloadPolygonPayload, IRapidPayloadScrubPayload, IRapidPayloadTranscriptionPayload. 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 IRapidPayloadTranscriptionPayload
        try:
            instance.actual_instance = IRapidPayloadTranscriptionPayload.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IRapidPayloadScrubPayload
        try:
            instance.actual_instance = IRapidPayloadScrubPayload.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IRapidPayloadPolygonPayload
        try:
            instance.actual_instance = IRapidPayloadPolygonPayload.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IRapidPayloadNamedEntityPayload
        try:
            instance.actual_instance = IRapidPayloadNamedEntityPayload.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IRapidPayloadLocatePayload
        try:
            instance.actual_instance = IRapidPayloadLocatePayload.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IRapidPayloadLinePayload
        try:
            instance.actual_instance = IRapidPayloadLinePayload.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IRapidPayloadFreeTextPayload
        try:
            instance.actual_instance = IRapidPayloadFreeTextPayload.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IRapidPayloadComparePayload
        try:
            instance.actual_instance = IRapidPayloadComparePayload.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IRapidPayloadClassifyPayload
        try:
            instance.actual_instance = IRapidPayloadClassifyPayload.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IRapidPayloadBoundingBoxPayload
        try:
            instance.actual_instance = IRapidPayloadBoundingBoxPayload.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 IRapidPayload with oneOf schemas: IRapidPayloadBoundingBoxPayload, IRapidPayloadClassifyPayload, IRapidPayloadComparePayload, IRapidPayloadFreeTextPayload, IRapidPayloadLinePayload, IRapidPayloadLocatePayload, IRapidPayloadNamedEntityPayload, IRapidPayloadPolygonPayload, IRapidPayloadScrubPayload, IRapidPayloadTranscriptionPayload. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when deserializing the JSON string into IRapidPayload with oneOf schemas: IRapidPayloadBoundingBoxPayload, IRapidPayloadClassifyPayload, IRapidPayloadComparePayload, IRapidPayloadFreeTextPayload, IRapidPayloadLinePayload, IRapidPayloadLocatePayload, IRapidPayloadNamedEntityPayload, IRapidPayloadPolygonPayload, IRapidPayloadScrubPayload, IRapidPayloadTranscriptionPayload. 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], IRapidPayloadBoundingBoxPayload, IRapidPayloadClassifyPayload, IRapidPayloadComparePayload, IRapidPayloadFreeTextPayload, IRapidPayloadLinePayload, IRapidPayloadLocatePayload, IRapidPayloadNamedEntityPayload, IRapidPayloadPolygonPayload, IRapidPayloadScrubPayload, IRapidPayloadTranscriptionPayload]]:
        """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())


