# 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_user_filter_model_age_user_filter_model import IUserFilterModelAgeUserFilterModel
from rapidata.api_client.models.i_user_filter_model_campaign_user_filter_model import IUserFilterModelCampaignUserFilterModel
from rapidata.api_client.models.i_user_filter_model_country_user_filter_model import IUserFilterModelCountryUserFilterModel
from rapidata.api_client.models.i_user_filter_model_custom_user_filter_model import IUserFilterModelCustomUserFilterModel
from rapidata.api_client.models.i_user_filter_model_gender_user_filter_model import IUserFilterModelGenderUserFilterModel
from rapidata.api_client.models.i_user_filter_model_language_user_filter_model import IUserFilterModelLanguageUserFilterModel
from rapidata.api_client.models.i_user_filter_model_new_user_filter_model import IUserFilterModelNewUserFilterModel
from rapidata.api_client.models.i_user_filter_model_response_count_user_filter_model import IUserFilterModelResponseCountUserFilterModel
from rapidata.api_client.models.i_user_filter_model_user_score_user_filter_model import IUserFilterModelUserScoreUserFilterModel
from pydantic import StrictStr, Field
from typing import Union, List, Set, Optional, Dict
from typing_extensions import Literal, Self

IUSERFILTERMODEL_ONE_OF_SCHEMAS = ["IUserFilterModelAgeUserFilterModel", "IUserFilterModelAndUserFilterModel", "IUserFilterModelCampaignUserFilterModel", "IUserFilterModelCountryUserFilterModel", "IUserFilterModelCustomUserFilterModel", "IUserFilterModelGenderUserFilterModel", "IUserFilterModelLanguageUserFilterModel", "IUserFilterModelNewUserFilterModel", "IUserFilterModelNotUserFilterModel", "IUserFilterModelOrUserFilterModel", "IUserFilterModelResponseCountUserFilterModel", "IUserFilterModelUserScoreUserFilterModel"]

class IUserFilterModel(BaseModel):
    """
    IUserFilterModel
    """
    # data type: IUserFilterModelAgeUserFilterModel
    oneof_schema_1_validator: Optional[IUserFilterModelAgeUserFilterModel] = None
    # data type: IUserFilterModelAndUserFilterModel
    oneof_schema_2_validator: Optional[IUserFilterModelAndUserFilterModel] = None
    # data type: IUserFilterModelCampaignUserFilterModel
    oneof_schema_3_validator: Optional[IUserFilterModelCampaignUserFilterModel] = None
    # data type: IUserFilterModelCountryUserFilterModel
    oneof_schema_4_validator: Optional[IUserFilterModelCountryUserFilterModel] = None
    # data type: IUserFilterModelCustomUserFilterModel
    oneof_schema_5_validator: Optional[IUserFilterModelCustomUserFilterModel] = None
    # data type: IUserFilterModelGenderUserFilterModel
    oneof_schema_6_validator: Optional[IUserFilterModelGenderUserFilterModel] = None
    # data type: IUserFilterModelLanguageUserFilterModel
    oneof_schema_7_validator: Optional[IUserFilterModelLanguageUserFilterModel] = None
    # data type: IUserFilterModelNewUserFilterModel
    oneof_schema_8_validator: Optional[IUserFilterModelNewUserFilterModel] = None
    # data type: IUserFilterModelNotUserFilterModel
    oneof_schema_9_validator: Optional[IUserFilterModelNotUserFilterModel] = None
    # data type: IUserFilterModelOrUserFilterModel
    oneof_schema_10_validator: Optional[IUserFilterModelOrUserFilterModel] = None
    # data type: IUserFilterModelResponseCountUserFilterModel
    oneof_schema_11_validator: Optional[IUserFilterModelResponseCountUserFilterModel] = None
    # data type: IUserFilterModelUserScoreUserFilterModel
    oneof_schema_12_validator: Optional[IUserFilterModelUserScoreUserFilterModel] = None
    actual_instance: Optional[Union[IUserFilterModelAgeUserFilterModel, IUserFilterModelAndUserFilterModel, IUserFilterModelCampaignUserFilterModel, IUserFilterModelCountryUserFilterModel, IUserFilterModelCustomUserFilterModel, IUserFilterModelGenderUserFilterModel, IUserFilterModelLanguageUserFilterModel, IUserFilterModelNewUserFilterModel, IUserFilterModelNotUserFilterModel, IUserFilterModelOrUserFilterModel, IUserFilterModelResponseCountUserFilterModel, IUserFilterModelUserScoreUserFilterModel]] = None
    one_of_schemas: Set[str] = { "IUserFilterModelAgeUserFilterModel", "IUserFilterModelAndUserFilterModel", "IUserFilterModelCampaignUserFilterModel", "IUserFilterModelCountryUserFilterModel", "IUserFilterModelCustomUserFilterModel", "IUserFilterModelGenderUserFilterModel", "IUserFilterModelLanguageUserFilterModel", "IUserFilterModelNewUserFilterModel", "IUserFilterModelNotUserFilterModel", "IUserFilterModelOrUserFilterModel", "IUserFilterModelResponseCountUserFilterModel", "IUserFilterModelUserScoreUserFilterModel" }

    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 = IUserFilterModel.model_construct()
        error_messages = []
        match = 0
        # validate data type: IUserFilterModelAgeUserFilterModel
        if not isinstance(v, IUserFilterModelAgeUserFilterModel):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IUserFilterModelAgeUserFilterModel`")
        else:
            match += 1
        # validate data type: IUserFilterModelAndUserFilterModel
        if not isinstance(v, IUserFilterModelAndUserFilterModel):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IUserFilterModelAndUserFilterModel`")
        else:
            match += 1
        # validate data type: IUserFilterModelCampaignUserFilterModel
        if not isinstance(v, IUserFilterModelCampaignUserFilterModel):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IUserFilterModelCampaignUserFilterModel`")
        else:
            match += 1
        # validate data type: IUserFilterModelCountryUserFilterModel
        if not isinstance(v, IUserFilterModelCountryUserFilterModel):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IUserFilterModelCountryUserFilterModel`")
        else:
            match += 1
        # validate data type: IUserFilterModelCustomUserFilterModel
        if not isinstance(v, IUserFilterModelCustomUserFilterModel):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IUserFilterModelCustomUserFilterModel`")
        else:
            match += 1
        # validate data type: IUserFilterModelGenderUserFilterModel
        if not isinstance(v, IUserFilterModelGenderUserFilterModel):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IUserFilterModelGenderUserFilterModel`")
        else:
            match += 1
        # validate data type: IUserFilterModelLanguageUserFilterModel
        if not isinstance(v, IUserFilterModelLanguageUserFilterModel):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IUserFilterModelLanguageUserFilterModel`")
        else:
            match += 1
        # validate data type: IUserFilterModelNewUserFilterModel
        if not isinstance(v, IUserFilterModelNewUserFilterModel):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IUserFilterModelNewUserFilterModel`")
        else:
            match += 1
        # validate data type: IUserFilterModelNotUserFilterModel
        if not isinstance(v, IUserFilterModelNotUserFilterModel):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IUserFilterModelNotUserFilterModel`")
        else:
            match += 1
        # validate data type: IUserFilterModelOrUserFilterModel
        if not isinstance(v, IUserFilterModelOrUserFilterModel):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IUserFilterModelOrUserFilterModel`")
        else:
            match += 1
        # validate data type: IUserFilterModelResponseCountUserFilterModel
        if not isinstance(v, IUserFilterModelResponseCountUserFilterModel):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IUserFilterModelResponseCountUserFilterModel`")
        else:
            match += 1
        # validate data type: IUserFilterModelUserScoreUserFilterModel
        if not isinstance(v, IUserFilterModelUserScoreUserFilterModel):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IUserFilterModelUserScoreUserFilterModel`")
        else:
            match += 1
        if match > 1:
            # more than 1 match
            raise ValueError("Multiple matches found when setting `actual_instance` in IUserFilterModel with oneOf schemas: IUserFilterModelAgeUserFilterModel, IUserFilterModelAndUserFilterModel, IUserFilterModelCampaignUserFilterModel, IUserFilterModelCountryUserFilterModel, IUserFilterModelCustomUserFilterModel, IUserFilterModelGenderUserFilterModel, IUserFilterModelLanguageUserFilterModel, IUserFilterModelNewUserFilterModel, IUserFilterModelNotUserFilterModel, IUserFilterModelOrUserFilterModel, IUserFilterModelResponseCountUserFilterModel, IUserFilterModelUserScoreUserFilterModel. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when setting `actual_instance` in IUserFilterModel with oneOf schemas: IUserFilterModelAgeUserFilterModel, IUserFilterModelAndUserFilterModel, IUserFilterModelCampaignUserFilterModel, IUserFilterModelCountryUserFilterModel, IUserFilterModelCustomUserFilterModel, IUserFilterModelGenderUserFilterModel, IUserFilterModelLanguageUserFilterModel, IUserFilterModelNewUserFilterModel, IUserFilterModelNotUserFilterModel, IUserFilterModelOrUserFilterModel, IUserFilterModelResponseCountUserFilterModel, IUserFilterModelUserScoreUserFilterModel. 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 IUserFilterModelAgeUserFilterModel
        try:
            instance.actual_instance = IUserFilterModelAgeUserFilterModel.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IUserFilterModelAndUserFilterModel
        try:
            instance.actual_instance = IUserFilterModelAndUserFilterModel.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IUserFilterModelCampaignUserFilterModel
        try:
            instance.actual_instance = IUserFilterModelCampaignUserFilterModel.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IUserFilterModelCountryUserFilterModel
        try:
            instance.actual_instance = IUserFilterModelCountryUserFilterModel.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IUserFilterModelCustomUserFilterModel
        try:
            instance.actual_instance = IUserFilterModelCustomUserFilterModel.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IUserFilterModelGenderUserFilterModel
        try:
            instance.actual_instance = IUserFilterModelGenderUserFilterModel.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IUserFilterModelLanguageUserFilterModel
        try:
            instance.actual_instance = IUserFilterModelLanguageUserFilterModel.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IUserFilterModelNewUserFilterModel
        try:
            instance.actual_instance = IUserFilterModelNewUserFilterModel.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IUserFilterModelNotUserFilterModel
        try:
            instance.actual_instance = IUserFilterModelNotUserFilterModel.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IUserFilterModelOrUserFilterModel
        try:
            instance.actual_instance = IUserFilterModelOrUserFilterModel.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IUserFilterModelResponseCountUserFilterModel
        try:
            instance.actual_instance = IUserFilterModelResponseCountUserFilterModel.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IUserFilterModelUserScoreUserFilterModel
        try:
            instance.actual_instance = IUserFilterModelUserScoreUserFilterModel.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 IUserFilterModel with oneOf schemas: IUserFilterModelAgeUserFilterModel, IUserFilterModelAndUserFilterModel, IUserFilterModelCampaignUserFilterModel, IUserFilterModelCountryUserFilterModel, IUserFilterModelCustomUserFilterModel, IUserFilterModelGenderUserFilterModel, IUserFilterModelLanguageUserFilterModel, IUserFilterModelNewUserFilterModel, IUserFilterModelNotUserFilterModel, IUserFilterModelOrUserFilterModel, IUserFilterModelResponseCountUserFilterModel, IUserFilterModelUserScoreUserFilterModel. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when deserializing the JSON string into IUserFilterModel with oneOf schemas: IUserFilterModelAgeUserFilterModel, IUserFilterModelAndUserFilterModel, IUserFilterModelCampaignUserFilterModel, IUserFilterModelCountryUserFilterModel, IUserFilterModelCustomUserFilterModel, IUserFilterModelGenderUserFilterModel, IUserFilterModelLanguageUserFilterModel, IUserFilterModelNewUserFilterModel, IUserFilterModelNotUserFilterModel, IUserFilterModelOrUserFilterModel, IUserFilterModelResponseCountUserFilterModel, IUserFilterModelUserScoreUserFilterModel. 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], IUserFilterModelAgeUserFilterModel, IUserFilterModelAndUserFilterModel, IUserFilterModelCampaignUserFilterModel, IUserFilterModelCountryUserFilterModel, IUserFilterModelCustomUserFilterModel, IUserFilterModelGenderUserFilterModel, IUserFilterModelLanguageUserFilterModel, IUserFilterModelNewUserFilterModel, IUserFilterModelNotUserFilterModel, IUserFilterModelOrUserFilterModel, IUserFilterModelResponseCountUserFilterModel, IUserFilterModelUserScoreUserFilterModel]]:
        """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_user_filter_model_and_user_filter_model import IUserFilterModelAndUserFilterModel
from rapidata.api_client.models.i_user_filter_model_not_user_filter_model import IUserFilterModelNotUserFilterModel
from rapidata.api_client.models.i_user_filter_model_or_user_filter_model import IUserFilterModelOrUserFilterModel
# TODO: Rewrite to not use raise_errors
IUserFilterModel.model_rebuild(raise_errors=False)

