# 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.age_user_filter_model import AgeUserFilterModel
from rapidata.api_client.models.campaign_user_filter_model import CampaignUserFilterModel
from rapidata.api_client.models.country_user_filter_model import CountryUserFilterModel
from rapidata.api_client.models.custom_user_filter_model import CustomUserFilterModel
from rapidata.api_client.models.gender_user_filter_model import GenderUserFilterModel
from rapidata.api_client.models.language_user_filter_model import LanguageUserFilterModel
from rapidata.api_client.models.new_user_filter_model1 import NewUserFilterModel1
from rapidata.api_client.models.user_score_user_filter_model import UserScoreUserFilterModel
from pydantic import StrictStr, Field
from typing import Union, List, Set, Optional, Dict
from typing_extensions import Literal, Self

ADDCAMPAIGNMODELUSERFILTERSINNER_ONE_OF_SCHEMAS = ["AgeUserFilterModel", "CampaignUserFilterModel", "CountryUserFilterModel", "CustomUserFilterModel", "GenderUserFilterModel", "LanguageUserFilterModel", "NewUserFilterModel1", "UserScoreUserFilterModel"]

class AddCampaignModelUserFiltersInner(BaseModel):
    """
    AddCampaignModelUserFiltersInner
    """
    # data type: AgeUserFilterModel
    oneof_schema_1_validator: Optional[AgeUserFilterModel] = None
    # data type: CampaignUserFilterModel
    oneof_schema_2_validator: Optional[CampaignUserFilterModel] = None
    # data type: CountryUserFilterModel
    oneof_schema_3_validator: Optional[CountryUserFilterModel] = None
    # data type: CustomUserFilterModel
    oneof_schema_4_validator: Optional[CustomUserFilterModel] = None
    # data type: GenderUserFilterModel
    oneof_schema_5_validator: Optional[GenderUserFilterModel] = None
    # data type: LanguageUserFilterModel
    oneof_schema_6_validator: Optional[LanguageUserFilterModel] = None
    # data type: NewUserFilterModel1
    oneof_schema_7_validator: Optional[NewUserFilterModel1] = None
    # data type: UserScoreUserFilterModel
    oneof_schema_8_validator: Optional[UserScoreUserFilterModel] = None
    actual_instance: Optional[Union[AgeUserFilterModel, CampaignUserFilterModel, CountryUserFilterModel, CustomUserFilterModel, GenderUserFilterModel, LanguageUserFilterModel, NewUserFilterModel1, UserScoreUserFilterModel]] = None
    one_of_schemas: Set[str] = { "AgeUserFilterModel", "CampaignUserFilterModel", "CountryUserFilterModel", "CustomUserFilterModel", "GenderUserFilterModel", "LanguageUserFilterModel", "NewUserFilterModel1", "UserScoreUserFilterModel" }

    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 = AddCampaignModelUserFiltersInner.model_construct()
        error_messages = []
        match = 0
        # validate data type: AgeUserFilterModel
        if not isinstance(v, AgeUserFilterModel):
            error_messages.append(f"Error! Input type `{type(v)}` is not `AgeUserFilterModel`")
        else:
            match += 1
        # validate data type: CampaignUserFilterModel
        if not isinstance(v, CampaignUserFilterModel):
            error_messages.append(f"Error! Input type `{type(v)}` is not `CampaignUserFilterModel`")
        else:
            match += 1
        # validate data type: CountryUserFilterModel
        if not isinstance(v, CountryUserFilterModel):
            error_messages.append(f"Error! Input type `{type(v)}` is not `CountryUserFilterModel`")
        else:
            match += 1
        # validate data type: CustomUserFilterModel
        if not isinstance(v, CustomUserFilterModel):
            error_messages.append(f"Error! Input type `{type(v)}` is not `CustomUserFilterModel`")
        else:
            match += 1
        # validate data type: GenderUserFilterModel
        if not isinstance(v, GenderUserFilterModel):
            error_messages.append(f"Error! Input type `{type(v)}` is not `GenderUserFilterModel`")
        else:
            match += 1
        # validate data type: LanguageUserFilterModel
        if not isinstance(v, LanguageUserFilterModel):
            error_messages.append(f"Error! Input type `{type(v)}` is not `LanguageUserFilterModel`")
        else:
            match += 1
        # validate data type: NewUserFilterModel1
        if not isinstance(v, NewUserFilterModel1):
            error_messages.append(f"Error! Input type `{type(v)}` is not `NewUserFilterModel1`")
        else:
            match += 1
        # validate data type: UserScoreUserFilterModel
        if not isinstance(v, UserScoreUserFilterModel):
            error_messages.append(f"Error! Input type `{type(v)}` is not `UserScoreUserFilterModel`")
        else:
            match += 1
        if match > 1:
            # more than 1 match
            raise ValueError("Multiple matches found when setting `actual_instance` in AddCampaignModelUserFiltersInner with oneOf schemas: AgeUserFilterModel, CampaignUserFilterModel, CountryUserFilterModel, CustomUserFilterModel, GenderUserFilterModel, LanguageUserFilterModel, NewUserFilterModel1, UserScoreUserFilterModel. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when setting `actual_instance` in AddCampaignModelUserFiltersInner with oneOf schemas: AgeUserFilterModel, CampaignUserFilterModel, CountryUserFilterModel, CustomUserFilterModel, GenderUserFilterModel, LanguageUserFilterModel, NewUserFilterModel1, UserScoreUserFilterModel. 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 AgeUserFilterModel
        try:
            instance.actual_instance = AgeUserFilterModel.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into CampaignUserFilterModel
        try:
            instance.actual_instance = CampaignUserFilterModel.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into CountryUserFilterModel
        try:
            instance.actual_instance = CountryUserFilterModel.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into CustomUserFilterModel
        try:
            instance.actual_instance = CustomUserFilterModel.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into GenderUserFilterModel
        try:
            instance.actual_instance = GenderUserFilterModel.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into LanguageUserFilterModel
        try:
            instance.actual_instance = LanguageUserFilterModel.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into NewUserFilterModel1
        try:
            instance.actual_instance = NewUserFilterModel1.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into UserScoreUserFilterModel
        try:
            instance.actual_instance = UserScoreUserFilterModel.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 AddCampaignModelUserFiltersInner with oneOf schemas: AgeUserFilterModel, CampaignUserFilterModel, CountryUserFilterModel, CustomUserFilterModel, GenderUserFilterModel, LanguageUserFilterModel, NewUserFilterModel1, UserScoreUserFilterModel. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when deserializing the JSON string into AddCampaignModelUserFiltersInner with oneOf schemas: AgeUserFilterModel, CampaignUserFilterModel, CountryUserFilterModel, CustomUserFilterModel, GenderUserFilterModel, LanguageUserFilterModel, NewUserFilterModel1, UserScoreUserFilterModel. 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], AgeUserFilterModel, CampaignUserFilterModel, CountryUserFilterModel, CustomUserFilterModel, GenderUserFilterModel, LanguageUserFilterModel, NewUserFilterModel1, UserScoreUserFilterModel]]:
        """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())


