# 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_selection_demographic_selection import ISelectionDemographicSelection
from rapidata.api_client.models.i_selection_effort_capped_selection import ISelectionEffortCappedSelection
from rapidata.api_client.models.i_selection_labeling_selection import ISelectionLabelingSelection
from rapidata.api_client.models.i_selection_static_selection import ISelectionStaticSelection
from rapidata.api_client.models.i_selection_validation_selection import ISelectionValidationSelection
from pydantic import StrictStr, Field
from typing import Union, List, Set, Optional, Dict
from typing_extensions import Literal, Self

ISELECTION_ONE_OF_SCHEMAS = ["ISelectionAbTestSelection", "ISelectionCappedSelection", "ISelectionConditionalValidationSelection", "ISelectionDemographicSelection", "ISelectionEffortCappedSelection", "ISelectionLabelingSelection", "ISelectionShufflingSelection", "ISelectionStaticSelection", "ISelectionValidationSelection"]

class ISelection(BaseModel):
    """
    ISelection
    """
    # data type: ISelectionAbTestSelection
    oneof_schema_1_validator: Optional[ISelectionAbTestSelection] = None
    # data type: ISelectionCappedSelection
    oneof_schema_2_validator: Optional[ISelectionCappedSelection] = None
    # data type: ISelectionConditionalValidationSelection
    oneof_schema_3_validator: Optional[ISelectionConditionalValidationSelection] = None
    # data type: ISelectionDemographicSelection
    oneof_schema_4_validator: Optional[ISelectionDemographicSelection] = None
    # data type: ISelectionEffortCappedSelection
    oneof_schema_5_validator: Optional[ISelectionEffortCappedSelection] = None
    # data type: ISelectionLabelingSelection
    oneof_schema_6_validator: Optional[ISelectionLabelingSelection] = None
    # data type: ISelectionShufflingSelection
    oneof_schema_7_validator: Optional[ISelectionShufflingSelection] = None
    # data type: ISelectionStaticSelection
    oneof_schema_8_validator: Optional[ISelectionStaticSelection] = None
    # data type: ISelectionValidationSelection
    oneof_schema_9_validator: Optional[ISelectionValidationSelection] = None
    actual_instance: Optional[Union[ISelectionAbTestSelection, ISelectionCappedSelection, ISelectionConditionalValidationSelection, ISelectionDemographicSelection, ISelectionEffortCappedSelection, ISelectionLabelingSelection, ISelectionShufflingSelection, ISelectionStaticSelection, ISelectionValidationSelection]] = None
    one_of_schemas: Set[str] = { "ISelectionAbTestSelection", "ISelectionCappedSelection", "ISelectionConditionalValidationSelection", "ISelectionDemographicSelection", "ISelectionEffortCappedSelection", "ISelectionLabelingSelection", "ISelectionShufflingSelection", "ISelectionStaticSelection", "ISelectionValidationSelection" }

    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 = ISelection.model_construct()
        error_messages = []
        match = 0
        # validate data type: ISelectionAbTestSelection
        if not isinstance(v, ISelectionAbTestSelection):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ISelectionAbTestSelection`")
        else:
            match += 1
        # validate data type: ISelectionCappedSelection
        if not isinstance(v, ISelectionCappedSelection):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ISelectionCappedSelection`")
        else:
            match += 1
        # validate data type: ISelectionConditionalValidationSelection
        if not isinstance(v, ISelectionConditionalValidationSelection):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ISelectionConditionalValidationSelection`")
        else:
            match += 1
        # validate data type: ISelectionDemographicSelection
        if not isinstance(v, ISelectionDemographicSelection):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ISelectionDemographicSelection`")
        else:
            match += 1
        # validate data type: ISelectionEffortCappedSelection
        if not isinstance(v, ISelectionEffortCappedSelection):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ISelectionEffortCappedSelection`")
        else:
            match += 1
        # validate data type: ISelectionLabelingSelection
        if not isinstance(v, ISelectionLabelingSelection):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ISelectionLabelingSelection`")
        else:
            match += 1
        # validate data type: ISelectionShufflingSelection
        if not isinstance(v, ISelectionShufflingSelection):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ISelectionShufflingSelection`")
        else:
            match += 1
        # validate data type: ISelectionStaticSelection
        if not isinstance(v, ISelectionStaticSelection):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ISelectionStaticSelection`")
        else:
            match += 1
        # validate data type: ISelectionValidationSelection
        if not isinstance(v, ISelectionValidationSelection):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ISelectionValidationSelection`")
        else:
            match += 1
        if match > 1:
            # more than 1 match
            raise ValueError("Multiple matches found when setting `actual_instance` in ISelection with oneOf schemas: ISelectionAbTestSelection, ISelectionCappedSelection, ISelectionConditionalValidationSelection, ISelectionDemographicSelection, ISelectionEffortCappedSelection, ISelectionLabelingSelection, ISelectionShufflingSelection, ISelectionStaticSelection, ISelectionValidationSelection. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when setting `actual_instance` in ISelection with oneOf schemas: ISelectionAbTestSelection, ISelectionCappedSelection, ISelectionConditionalValidationSelection, ISelectionDemographicSelection, ISelectionEffortCappedSelection, ISelectionLabelingSelection, ISelectionShufflingSelection, ISelectionStaticSelection, ISelectionValidationSelection. 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 ISelectionAbTestSelection
        try:
            instance.actual_instance = ISelectionAbTestSelection.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ISelectionCappedSelection
        try:
            instance.actual_instance = ISelectionCappedSelection.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ISelectionConditionalValidationSelection
        try:
            instance.actual_instance = ISelectionConditionalValidationSelection.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ISelectionDemographicSelection
        try:
            instance.actual_instance = ISelectionDemographicSelection.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ISelectionEffortCappedSelection
        try:
            instance.actual_instance = ISelectionEffortCappedSelection.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ISelectionLabelingSelection
        try:
            instance.actual_instance = ISelectionLabelingSelection.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ISelectionShufflingSelection
        try:
            instance.actual_instance = ISelectionShufflingSelection.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ISelectionStaticSelection
        try:
            instance.actual_instance = ISelectionStaticSelection.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ISelectionValidationSelection
        try:
            instance.actual_instance = ISelectionValidationSelection.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 ISelection with oneOf schemas: ISelectionAbTestSelection, ISelectionCappedSelection, ISelectionConditionalValidationSelection, ISelectionDemographicSelection, ISelectionEffortCappedSelection, ISelectionLabelingSelection, ISelectionShufflingSelection, ISelectionStaticSelection, ISelectionValidationSelection. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when deserializing the JSON string into ISelection with oneOf schemas: ISelectionAbTestSelection, ISelectionCappedSelection, ISelectionConditionalValidationSelection, ISelectionDemographicSelection, ISelectionEffortCappedSelection, ISelectionLabelingSelection, ISelectionShufflingSelection, ISelectionStaticSelection, ISelectionValidationSelection. 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], ISelectionAbTestSelection, ISelectionCappedSelection, ISelectionConditionalValidationSelection, ISelectionDemographicSelection, ISelectionEffortCappedSelection, ISelectionLabelingSelection, ISelectionShufflingSelection, ISelectionStaticSelection, ISelectionValidationSelection]]:
        """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())

from rapidata.api_client.models.i_selection_ab_test_selection import ISelectionAbTestSelection
from rapidata.api_client.models.i_selection_capped_selection import ISelectionCappedSelection
from rapidata.api_client.models.i_selection_conditional_validation_selection import ISelectionConditionalValidationSelection
from rapidata.api_client.models.i_selection_shuffling_selection import ISelectionShufflingSelection
# TODO: Rewrite to not use raise_errors
ISelection.model_rebuild(raise_errors=False)

