# 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_campaign_filter_campaign_filter import ICampaignFilterCampaignFilter
from rapidata.api_client.models.i_campaign_filter_campaign_session_count_filter import ICampaignFilterCampaignSessionCountFilter
from rapidata.api_client.models.i_campaign_filter_country_filter import ICampaignFilterCountryFilter
from rapidata.api_client.models.i_campaign_filter_demographic_filter import ICampaignFilterDemographicFilter
from rapidata.api_client.models.i_campaign_filter_device_filter import ICampaignFilterDeviceFilter
from rapidata.api_client.models.i_campaign_filter_language_filter import ICampaignFilterLanguageFilter
from rapidata.api_client.models.i_campaign_filter_new_user_filter import ICampaignFilterNewUserFilter
from rapidata.api_client.models.i_campaign_filter_response_count_filter import ICampaignFilterResponseCountFilter
from rapidata.api_client.models.i_campaign_filter_user_action_restriction_filter import ICampaignFilterUserActionRestrictionFilter
from rapidata.api_client.models.i_campaign_filter_user_score_filter import ICampaignFilterUserScoreFilter
from pydantic import StrictStr, Field
from typing import Union, List, Set, Optional, Dict
from typing_extensions import Literal, Self

ICAMPAIGNFILTER_ONE_OF_SCHEMAS = ["ICampaignFilterAndFilter", "ICampaignFilterCampaignFilter", "ICampaignFilterCampaignSessionCountFilter", "ICampaignFilterCountryFilter", "ICampaignFilterDemographicFilter", "ICampaignFilterDeviceFilter", "ICampaignFilterLanguageFilter", "ICampaignFilterNewUserFilter", "ICampaignFilterNotFilter", "ICampaignFilterOrFilter", "ICampaignFilterResponseCountFilter", "ICampaignFilterUserActionRestrictionFilter", "ICampaignFilterUserScoreFilter"]

class ICampaignFilter(BaseModel):
    """
    ICampaignFilter
    """
    # data type: ICampaignFilterAndFilter
    oneof_schema_1_validator: Optional[ICampaignFilterAndFilter] = None
    # data type: ICampaignFilterCampaignFilter
    oneof_schema_2_validator: Optional[ICampaignFilterCampaignFilter] = None
    # data type: ICampaignFilterCampaignSessionCountFilter
    oneof_schema_3_validator: Optional[ICampaignFilterCampaignSessionCountFilter] = None
    # data type: ICampaignFilterCountryFilter
    oneof_schema_4_validator: Optional[ICampaignFilterCountryFilter] = None
    # data type: ICampaignFilterDemographicFilter
    oneof_schema_5_validator: Optional[ICampaignFilterDemographicFilter] = None
    # data type: ICampaignFilterDeviceFilter
    oneof_schema_6_validator: Optional[ICampaignFilterDeviceFilter] = None
    # data type: ICampaignFilterLanguageFilter
    oneof_schema_7_validator: Optional[ICampaignFilterLanguageFilter] = None
    # data type: ICampaignFilterNewUserFilter
    oneof_schema_8_validator: Optional[ICampaignFilterNewUserFilter] = None
    # data type: ICampaignFilterNotFilter
    oneof_schema_9_validator: Optional[ICampaignFilterNotFilter] = None
    # data type: ICampaignFilterOrFilter
    oneof_schema_10_validator: Optional[ICampaignFilterOrFilter] = None
    # data type: ICampaignFilterResponseCountFilter
    oneof_schema_11_validator: Optional[ICampaignFilterResponseCountFilter] = None
    # data type: ICampaignFilterUserActionRestrictionFilter
    oneof_schema_12_validator: Optional[ICampaignFilterUserActionRestrictionFilter] = None
    # data type: ICampaignFilterUserScoreFilter
    oneof_schema_13_validator: Optional[ICampaignFilterUserScoreFilter] = None
    actual_instance: Optional[Union[ICampaignFilterAndFilter, ICampaignFilterCampaignFilter, ICampaignFilterCampaignSessionCountFilter, ICampaignFilterCountryFilter, ICampaignFilterDemographicFilter, ICampaignFilterDeviceFilter, ICampaignFilterLanguageFilter, ICampaignFilterNewUserFilter, ICampaignFilterNotFilter, ICampaignFilterOrFilter, ICampaignFilterResponseCountFilter, ICampaignFilterUserActionRestrictionFilter, ICampaignFilterUserScoreFilter]] = None
    one_of_schemas: Set[str] = { "ICampaignFilterAndFilter", "ICampaignFilterCampaignFilter", "ICampaignFilterCampaignSessionCountFilter", "ICampaignFilterCountryFilter", "ICampaignFilterDemographicFilter", "ICampaignFilterDeviceFilter", "ICampaignFilterLanguageFilter", "ICampaignFilterNewUserFilter", "ICampaignFilterNotFilter", "ICampaignFilterOrFilter", "ICampaignFilterResponseCountFilter", "ICampaignFilterUserActionRestrictionFilter", "ICampaignFilterUserScoreFilter" }

    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 = ICampaignFilter.model_construct()
        error_messages = []
        match = 0
        # validate data type: ICampaignFilterAndFilter
        if not isinstance(v, ICampaignFilterAndFilter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ICampaignFilterAndFilter`")
        else:
            match += 1
        # validate data type: ICampaignFilterCampaignFilter
        if not isinstance(v, ICampaignFilterCampaignFilter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ICampaignFilterCampaignFilter`")
        else:
            match += 1
        # validate data type: ICampaignFilterCampaignSessionCountFilter
        if not isinstance(v, ICampaignFilterCampaignSessionCountFilter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ICampaignFilterCampaignSessionCountFilter`")
        else:
            match += 1
        # validate data type: ICampaignFilterCountryFilter
        if not isinstance(v, ICampaignFilterCountryFilter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ICampaignFilterCountryFilter`")
        else:
            match += 1
        # validate data type: ICampaignFilterDemographicFilter
        if not isinstance(v, ICampaignFilterDemographicFilter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ICampaignFilterDemographicFilter`")
        else:
            match += 1
        # validate data type: ICampaignFilterDeviceFilter
        if not isinstance(v, ICampaignFilterDeviceFilter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ICampaignFilterDeviceFilter`")
        else:
            match += 1
        # validate data type: ICampaignFilterLanguageFilter
        if not isinstance(v, ICampaignFilterLanguageFilter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ICampaignFilterLanguageFilter`")
        else:
            match += 1
        # validate data type: ICampaignFilterNewUserFilter
        if not isinstance(v, ICampaignFilterNewUserFilter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ICampaignFilterNewUserFilter`")
        else:
            match += 1
        # validate data type: ICampaignFilterNotFilter
        if not isinstance(v, ICampaignFilterNotFilter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ICampaignFilterNotFilter`")
        else:
            match += 1
        # validate data type: ICampaignFilterOrFilter
        if not isinstance(v, ICampaignFilterOrFilter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ICampaignFilterOrFilter`")
        else:
            match += 1
        # validate data type: ICampaignFilterResponseCountFilter
        if not isinstance(v, ICampaignFilterResponseCountFilter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ICampaignFilterResponseCountFilter`")
        else:
            match += 1
        # validate data type: ICampaignFilterUserActionRestrictionFilter
        if not isinstance(v, ICampaignFilterUserActionRestrictionFilter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ICampaignFilterUserActionRestrictionFilter`")
        else:
            match += 1
        # validate data type: ICampaignFilterUserScoreFilter
        if not isinstance(v, ICampaignFilterUserScoreFilter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ICampaignFilterUserScoreFilter`")
        else:
            match += 1
        if match > 1:
            # more than 1 match
            raise ValueError("Multiple matches found when setting `actual_instance` in ICampaignFilter with oneOf schemas: ICampaignFilterAndFilter, ICampaignFilterCampaignFilter, ICampaignFilterCampaignSessionCountFilter, ICampaignFilterCountryFilter, ICampaignFilterDemographicFilter, ICampaignFilterDeviceFilter, ICampaignFilterLanguageFilter, ICampaignFilterNewUserFilter, ICampaignFilterNotFilter, ICampaignFilterOrFilter, ICampaignFilterResponseCountFilter, ICampaignFilterUserActionRestrictionFilter, ICampaignFilterUserScoreFilter. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when setting `actual_instance` in ICampaignFilter with oneOf schemas: ICampaignFilterAndFilter, ICampaignFilterCampaignFilter, ICampaignFilterCampaignSessionCountFilter, ICampaignFilterCountryFilter, ICampaignFilterDemographicFilter, ICampaignFilterDeviceFilter, ICampaignFilterLanguageFilter, ICampaignFilterNewUserFilter, ICampaignFilterNotFilter, ICampaignFilterOrFilter, ICampaignFilterResponseCountFilter, ICampaignFilterUserActionRestrictionFilter, ICampaignFilterUserScoreFilter. 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 ICampaignFilterAndFilter
        try:
            instance.actual_instance = ICampaignFilterAndFilter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ICampaignFilterCampaignFilter
        try:
            instance.actual_instance = ICampaignFilterCampaignFilter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ICampaignFilterCampaignSessionCountFilter
        try:
            instance.actual_instance = ICampaignFilterCampaignSessionCountFilter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ICampaignFilterCountryFilter
        try:
            instance.actual_instance = ICampaignFilterCountryFilter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ICampaignFilterDemographicFilter
        try:
            instance.actual_instance = ICampaignFilterDemographicFilter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ICampaignFilterDeviceFilter
        try:
            instance.actual_instance = ICampaignFilterDeviceFilter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ICampaignFilterLanguageFilter
        try:
            instance.actual_instance = ICampaignFilterLanguageFilter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ICampaignFilterNewUserFilter
        try:
            instance.actual_instance = ICampaignFilterNewUserFilter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ICampaignFilterNotFilter
        try:
            instance.actual_instance = ICampaignFilterNotFilter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ICampaignFilterOrFilter
        try:
            instance.actual_instance = ICampaignFilterOrFilter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ICampaignFilterResponseCountFilter
        try:
            instance.actual_instance = ICampaignFilterResponseCountFilter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ICampaignFilterUserActionRestrictionFilter
        try:
            instance.actual_instance = ICampaignFilterUserActionRestrictionFilter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ICampaignFilterUserScoreFilter
        try:
            instance.actual_instance = ICampaignFilterUserScoreFilter.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 ICampaignFilter with oneOf schemas: ICampaignFilterAndFilter, ICampaignFilterCampaignFilter, ICampaignFilterCampaignSessionCountFilter, ICampaignFilterCountryFilter, ICampaignFilterDemographicFilter, ICampaignFilterDeviceFilter, ICampaignFilterLanguageFilter, ICampaignFilterNewUserFilter, ICampaignFilterNotFilter, ICampaignFilterOrFilter, ICampaignFilterResponseCountFilter, ICampaignFilterUserActionRestrictionFilter, ICampaignFilterUserScoreFilter. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when deserializing the JSON string into ICampaignFilter with oneOf schemas: ICampaignFilterAndFilter, ICampaignFilterCampaignFilter, ICampaignFilterCampaignSessionCountFilter, ICampaignFilterCountryFilter, ICampaignFilterDemographicFilter, ICampaignFilterDeviceFilter, ICampaignFilterLanguageFilter, ICampaignFilterNewUserFilter, ICampaignFilterNotFilter, ICampaignFilterOrFilter, ICampaignFilterResponseCountFilter, ICampaignFilterUserActionRestrictionFilter, ICampaignFilterUserScoreFilter. 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], ICampaignFilterAndFilter, ICampaignFilterCampaignFilter, ICampaignFilterCampaignSessionCountFilter, ICampaignFilterCountryFilter, ICampaignFilterDemographicFilter, ICampaignFilterDeviceFilter, ICampaignFilterLanguageFilter, ICampaignFilterNewUserFilter, ICampaignFilterNotFilter, ICampaignFilterOrFilter, ICampaignFilterResponseCountFilter, ICampaignFilterUserActionRestrictionFilter, ICampaignFilterUserScoreFilter]]:
        """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_campaign_filter_and_filter import ICampaignFilterAndFilter
from rapidata.api_client.models.i_campaign_filter_not_filter import ICampaignFilterNotFilter
from rapidata.api_client.models.i_campaign_filter_or_filter import ICampaignFilterOrFilter
# TODO: Rewrite to not use raise_errors
ICampaignFilter.model_rebuild(raise_errors=False)

