# 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.conditional_validation_selection import ConditionalValidationSelection
from rapidata.api_client.models.demographic_selection import DemographicSelection
from rapidata.api_client.models.effort_capped_selection import EffortCappedSelection
from rapidata.api_client.models.labeling_selection import LabelingSelection
from rapidata.api_client.models.static_selection import StaticSelection
from rapidata.api_client.models.validation_selection import ValidationSelection
from pydantic import StrictStr, Field
from typing import Union, List, Set, Optional, Dict
from typing_extensions import Literal, Self

ABTESTSELECTIONAINNER_ONE_OF_SCHEMAS = ["AbTestSelection", "CappedSelection", "ConditionalValidationSelection", "DemographicSelection", "EffortCappedSelection", "LabelingSelection", "ShufflingSelection", "StaticSelection", "ValidationSelection"]

class AbTestSelectionAInner(BaseModel):
    """
    AbTestSelectionAInner
    """
    # data type: AbTestSelection
    oneof_schema_1_validator: Optional[AbTestSelection] = None
    # data type: CappedSelection
    oneof_schema_2_validator: Optional[CappedSelection] = None
    # data type: ConditionalValidationSelection
    oneof_schema_3_validator: Optional[ConditionalValidationSelection] = None
    # data type: DemographicSelection
    oneof_schema_4_validator: Optional[DemographicSelection] = None
    # data type: EffortCappedSelection
    oneof_schema_5_validator: Optional[EffortCappedSelection] = None
    # data type: LabelingSelection
    oneof_schema_6_validator: Optional[LabelingSelection] = None
    # data type: ShufflingSelection
    oneof_schema_7_validator: Optional[ShufflingSelection] = None
    # data type: StaticSelection
    oneof_schema_8_validator: Optional[StaticSelection] = None
    # data type: ValidationSelection
    oneof_schema_9_validator: Optional[ValidationSelection] = None
    actual_instance: Optional[Union[AbTestSelection, CappedSelection, ConditionalValidationSelection, DemographicSelection, EffortCappedSelection, LabelingSelection, ShufflingSelection, StaticSelection, ValidationSelection]] = None
    one_of_schemas: Set[str] = { "AbTestSelection", "CappedSelection", "ConditionalValidationSelection", "DemographicSelection", "EffortCappedSelection", "LabelingSelection", "ShufflingSelection", "StaticSelection", "ValidationSelection" }

    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 = AbTestSelectionAInner.model_construct()
        error_messages = []
        match = 0
        # validate data type: AbTestSelection
        if not isinstance(v, AbTestSelection):
            error_messages.append(f"Error! Input type `{type(v)}` is not `AbTestSelection`")
        else:
            match += 1
        # validate data type: CappedSelection
        if not isinstance(v, CappedSelection):
            error_messages.append(f"Error! Input type `{type(v)}` is not `CappedSelection`")
        else:
            match += 1
        # validate data type: ConditionalValidationSelection
        if not isinstance(v, ConditionalValidationSelection):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ConditionalValidationSelection`")
        else:
            match += 1
        # validate data type: DemographicSelection
        if not isinstance(v, DemographicSelection):
            error_messages.append(f"Error! Input type `{type(v)}` is not `DemographicSelection`")
        else:
            match += 1
        # validate data type: EffortCappedSelection
        if not isinstance(v, EffortCappedSelection):
            error_messages.append(f"Error! Input type `{type(v)}` is not `EffortCappedSelection`")
        else:
            match += 1
        # validate data type: LabelingSelection
        if not isinstance(v, LabelingSelection):
            error_messages.append(f"Error! Input type `{type(v)}` is not `LabelingSelection`")
        else:
            match += 1
        # validate data type: ShufflingSelection
        if not isinstance(v, ShufflingSelection):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ShufflingSelection`")
        else:
            match += 1
        # validate data type: StaticSelection
        if not isinstance(v, StaticSelection):
            error_messages.append(f"Error! Input type `{type(v)}` is not `StaticSelection`")
        else:
            match += 1
        # validate data type: ValidationSelection
        if not isinstance(v, ValidationSelection):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ValidationSelection`")
        else:
            match += 1
        if match > 1:
            # more than 1 match
            raise ValueError("Multiple matches found when setting `actual_instance` in AbTestSelectionAInner with oneOf schemas: AbTestSelection, CappedSelection, ConditionalValidationSelection, DemographicSelection, EffortCappedSelection, LabelingSelection, ShufflingSelection, StaticSelection, ValidationSelection. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when setting `actual_instance` in AbTestSelectionAInner with oneOf schemas: AbTestSelection, CappedSelection, ConditionalValidationSelection, DemographicSelection, EffortCappedSelection, LabelingSelection, ShufflingSelection, StaticSelection, ValidationSelection. 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 AbTestSelection
        try:
            instance.actual_instance = AbTestSelection.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into CappedSelection
        try:
            instance.actual_instance = CappedSelection.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ConditionalValidationSelection
        try:
            instance.actual_instance = ConditionalValidationSelection.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into DemographicSelection
        try:
            instance.actual_instance = DemographicSelection.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into EffortCappedSelection
        try:
            instance.actual_instance = EffortCappedSelection.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into LabelingSelection
        try:
            instance.actual_instance = LabelingSelection.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ShufflingSelection
        try:
            instance.actual_instance = ShufflingSelection.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into StaticSelection
        try:
            instance.actual_instance = StaticSelection.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ValidationSelection
        try:
            instance.actual_instance = ValidationSelection.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 AbTestSelectionAInner with oneOf schemas: AbTestSelection, CappedSelection, ConditionalValidationSelection, DemographicSelection, EffortCappedSelection, LabelingSelection, ShufflingSelection, StaticSelection, ValidationSelection. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when deserializing the JSON string into AbTestSelectionAInner with oneOf schemas: AbTestSelection, CappedSelection, ConditionalValidationSelection, DemographicSelection, EffortCappedSelection, LabelingSelection, ShufflingSelection, StaticSelection, ValidationSelection. 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], AbTestSelection, CappedSelection, ConditionalValidationSelection, DemographicSelection, EffortCappedSelection, LabelingSelection, ShufflingSelection, StaticSelection, ValidationSelection]]:
        """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.ab_test_selection import AbTestSelection
from rapidata.api_client.models.capped_selection import CappedSelection
from rapidata.api_client.models.shuffling_selection import ShufflingSelection
# TODO: Rewrite to not use raise_errors
AbTestSelectionAInner.model_rebuild(raise_errors=False)

