# 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.campaign_filter import CampaignFilter
from rapidata.api_client.models.country_filter import CountryFilter
from rapidata.api_client.models.demographic_filter import DemographicFilter
from rapidata.api_client.models.language_filter import LanguageFilter
from rapidata.api_client.models.new_user_filter import NewUserFilter
from rapidata.api_client.models.response_count_filter import ResponseCountFilter
from rapidata.api_client.models.user_action_restriction_filter import UserActionRestrictionFilter
from rapidata.api_client.models.user_score_filter import UserScoreFilter
from rapidata.api_client.models.user_state_filter import UserStateFilter
from pydantic import StrictStr, Field
from typing import Union, List, Set, Optional, Dict
from typing_extensions import Literal, Self

ANDFILTERFILTERSINNER_ONE_OF_SCHEMAS = ["AndFilter", "CampaignFilter", "CountryFilter", "DemographicFilter", "LanguageFilter", "NewUserFilter", "NotFilter", "OrFilter", "ResponseCountFilter", "UserActionRestrictionFilter", "UserScoreFilter", "UserStateFilter"]

class AndFilterFiltersInner(BaseModel):
    """
    AndFilterFiltersInner
    """
    # data type: AndFilter
    oneof_schema_1_validator: Optional[AndFilter] = None
    # data type: CampaignFilter
    oneof_schema_2_validator: Optional[CampaignFilter] = None
    # data type: CountryFilter
    oneof_schema_3_validator: Optional[CountryFilter] = None
    # data type: DemographicFilter
    oneof_schema_4_validator: Optional[DemographicFilter] = None
    # data type: LanguageFilter
    oneof_schema_5_validator: Optional[LanguageFilter] = None
    # data type: NewUserFilter
    oneof_schema_6_validator: Optional[NewUserFilter] = None
    # data type: NotFilter
    oneof_schema_7_validator: Optional[NotFilter] = None
    # data type: OrFilter
    oneof_schema_8_validator: Optional[OrFilter] = None
    # data type: ResponseCountFilter
    oneof_schema_9_validator: Optional[ResponseCountFilter] = None
    # data type: UserActionRestrictionFilter
    oneof_schema_10_validator: Optional[UserActionRestrictionFilter] = None
    # data type: UserScoreFilter
    oneof_schema_11_validator: Optional[UserScoreFilter] = None
    # data type: UserStateFilter
    oneof_schema_12_validator: Optional[UserStateFilter] = None
    actual_instance: Optional[Union[AndFilter, CampaignFilter, CountryFilter, DemographicFilter, LanguageFilter, NewUserFilter, NotFilter, OrFilter, ResponseCountFilter, UserActionRestrictionFilter, UserScoreFilter, UserStateFilter]] = None
    one_of_schemas: Set[str] = { "AndFilter", "CampaignFilter", "CountryFilter", "DemographicFilter", "LanguageFilter", "NewUserFilter", "NotFilter", "OrFilter", "ResponseCountFilter", "UserActionRestrictionFilter", "UserScoreFilter", "UserStateFilter" }

    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 = AndFilterFiltersInner.model_construct()
        error_messages = []
        match = 0
        # validate data type: AndFilter
        if not isinstance(v, AndFilter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `AndFilter`")
        else:
            match += 1
        # validate data type: CampaignFilter
        if not isinstance(v, CampaignFilter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `CampaignFilter`")
        else:
            match += 1
        # validate data type: CountryFilter
        if not isinstance(v, CountryFilter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `CountryFilter`")
        else:
            match += 1
        # validate data type: DemographicFilter
        if not isinstance(v, DemographicFilter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `DemographicFilter`")
        else:
            match += 1
        # validate data type: LanguageFilter
        if not isinstance(v, LanguageFilter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `LanguageFilter`")
        else:
            match += 1
        # validate data type: NewUserFilter
        if not isinstance(v, NewUserFilter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `NewUserFilter`")
        else:
            match += 1
        # validate data type: NotFilter
        if not isinstance(v, NotFilter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `NotFilter`")
        else:
            match += 1
        # validate data type: OrFilter
        if not isinstance(v, OrFilter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `OrFilter`")
        else:
            match += 1
        # validate data type: ResponseCountFilter
        if not isinstance(v, ResponseCountFilter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ResponseCountFilter`")
        else:
            match += 1
        # validate data type: UserActionRestrictionFilter
        if not isinstance(v, UserActionRestrictionFilter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `UserActionRestrictionFilter`")
        else:
            match += 1
        # validate data type: UserScoreFilter
        if not isinstance(v, UserScoreFilter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `UserScoreFilter`")
        else:
            match += 1
        # validate data type: UserStateFilter
        if not isinstance(v, UserStateFilter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `UserStateFilter`")
        else:
            match += 1
        if match > 1:
            # more than 1 match
            raise ValueError("Multiple matches found when setting `actual_instance` in AndFilterFiltersInner with oneOf schemas: AndFilter, CampaignFilter, CountryFilter, DemographicFilter, LanguageFilter, NewUserFilter, NotFilter, OrFilter, ResponseCountFilter, UserActionRestrictionFilter, UserScoreFilter, UserStateFilter. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when setting `actual_instance` in AndFilterFiltersInner with oneOf schemas: AndFilter, CampaignFilter, CountryFilter, DemographicFilter, LanguageFilter, NewUserFilter, NotFilter, OrFilter, ResponseCountFilter, UserActionRestrictionFilter, UserScoreFilter, UserStateFilter. 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 AndFilter
        try:
            instance.actual_instance = AndFilter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into CampaignFilter
        try:
            instance.actual_instance = CampaignFilter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into CountryFilter
        try:
            instance.actual_instance = CountryFilter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into DemographicFilter
        try:
            instance.actual_instance = DemographicFilter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into LanguageFilter
        try:
            instance.actual_instance = LanguageFilter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into NewUserFilter
        try:
            instance.actual_instance = NewUserFilter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into NotFilter
        try:
            instance.actual_instance = NotFilter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into OrFilter
        try:
            instance.actual_instance = OrFilter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ResponseCountFilter
        try:
            instance.actual_instance = ResponseCountFilter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into UserActionRestrictionFilter
        try:
            instance.actual_instance = UserActionRestrictionFilter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into UserScoreFilter
        try:
            instance.actual_instance = UserScoreFilter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into UserStateFilter
        try:
            instance.actual_instance = UserStateFilter.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 AndFilterFiltersInner with oneOf schemas: AndFilter, CampaignFilter, CountryFilter, DemographicFilter, LanguageFilter, NewUserFilter, NotFilter, OrFilter, ResponseCountFilter, UserActionRestrictionFilter, UserScoreFilter, UserStateFilter. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when deserializing the JSON string into AndFilterFiltersInner with oneOf schemas: AndFilter, CampaignFilter, CountryFilter, DemographicFilter, LanguageFilter, NewUserFilter, NotFilter, OrFilter, ResponseCountFilter, UserActionRestrictionFilter, UserScoreFilter, UserStateFilter. 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], AndFilter, CampaignFilter, CountryFilter, DemographicFilter, LanguageFilter, NewUserFilter, NotFilter, OrFilter, ResponseCountFilter, UserActionRestrictionFilter, UserScoreFilter, UserStateFilter]]:
        """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.and_filter import AndFilter
from rapidata.api_client.models.not_filter import NotFilter
from rapidata.api_client.models.or_filter import OrFilter
# TODO: Rewrite to not use raise_errors
AndFilterFiltersInner.model_rebuild(raise_errors=False)

