# coding: utf-8

"""
    AdInsightService

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 1.0.0
    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 openapi_client.models.adinsight.auction_segment import AuctionSegment
from openapi_client.models.adinsight.auction_segment_search_parameter import AuctionSegmentSearchParameter
from openapi_client.models.adinsight.category_search_parameter import CategorySearchParameter
from openapi_client.models.adinsight.competition_level import CompetitionLevel
from openapi_client.models.adinsight.competition_search_parameter import CompetitionSearchParameter
from openapi_client.models.adinsight.date_range_search_parameter import DateRangeSearchParameter
from openapi_client.models.adinsight.day_month_and_year import DayMonthAndYear
from openapi_client.models.adinsight.device_criterion import DeviceCriterion
from openapi_client.models.adinsight.device_search_parameter import DeviceSearchParameter
from openapi_client.models.adinsight.exclude_account_keywords_search_parameter import ExcludeAccountKeywordsSearchParameter
from openapi_client.models.adinsight.idea_text_search_parameter import IdeaTextSearchParameter
from openapi_client.models.adinsight.impression_share_search_parameter import ImpressionShareSearchParameter
from openapi_client.models.adinsight.keyword import Keyword
from openapi_client.models.adinsight.language_criterion import LanguageCriterion
from openapi_client.models.adinsight.language_search_parameter import LanguageSearchParameter
from openapi_client.models.adinsight.location_criterion import LocationCriterion
from openapi_client.models.adinsight.location_search_parameter import LocationSearchParameter
from openapi_client.models.adinsight.network_criterion import NetworkCriterion
from openapi_client.models.adinsight.network_search_parameter import NetworkSearchParameter
from openapi_client.models.adinsight.query_search_parameter import QuerySearchParameter
from openapi_client.models.adinsight.search_volume_search_parameter import SearchVolumeSearchParameter
from openapi_client.models.adinsight.suggested_bid_search_parameter import SuggestedBidSearchParameter
from openapi_client.models.adinsight.url_search_parameter import UrlSearchParameter
from pydantic import StrictStr, Field
from typing import Union, List, Set, Optional, Dict
from typing_extensions import Literal, Self

SearchParameter_ONE_OF_SCHEMAS = ["AuctionSegmentSearchParameter", "CategorySearchParameter", "CompetitionSearchParameter", "DateRangeSearchParameter", "DeviceSearchParameter", "ExcludeAccountKeywordsSearchParameter", "IdeaTextSearchParameter", "ImpressionShareSearchParameter", "LanguageSearchParameter", "LocationSearchParameter", "NetworkSearchParameter", "QuerySearchParameter", "SearchVolumeSearchParameter", "SuggestedBidSearchParameter", "UrlSearchParameter"]

class SearchParameter(BaseModel):
    """
    SearchParameter
    """
    # data type: AuctionSegmentSearchParameter
    oneof_schema_auction_segment_search_parameter_validator: Optional[AuctionSegmentSearchParameter] = None
    # data type: CategorySearchParameter
    oneof_schema_category_search_parameter_validator: Optional[CategorySearchParameter] = None
    # data type: CompetitionSearchParameter
    oneof_schema_competition_search_parameter_validator: Optional[CompetitionSearchParameter] = None
    # data type: DateRangeSearchParameter
    oneof_schema_date_range_search_parameter_validator: Optional[DateRangeSearchParameter] = None
    # data type: DeviceSearchParameter
    oneof_schema_device_search_parameter_validator: Optional[DeviceSearchParameter] = None
    # data type: ExcludeAccountKeywordsSearchParameter
    oneof_schema_exclude_account_keywords_search_parameter_validator: Optional[ExcludeAccountKeywordsSearchParameter] = None
    # data type: IdeaTextSearchParameter
    oneof_schema_idea_text_search_parameter_validator: Optional[IdeaTextSearchParameter] = None
    # data type: ImpressionShareSearchParameter
    oneof_schema_impression_share_search_parameter_validator: Optional[ImpressionShareSearchParameter] = None
    # data type: LanguageSearchParameter
    oneof_schema_language_search_parameter_validator: Optional[LanguageSearchParameter] = None
    # data type: LocationSearchParameter
    oneof_schema_location_search_parameter_validator: Optional[LocationSearchParameter] = None
    # data type: NetworkSearchParameter
    oneof_schema_network_search_parameter_validator: Optional[NetworkSearchParameter] = None
    # data type: QuerySearchParameter
    oneof_schema_query_search_parameter_validator: Optional[QuerySearchParameter] = None
    # data type: SearchVolumeSearchParameter
    oneof_schema_search_volume_search_parameter_validator: Optional[SearchVolumeSearchParameter] = None
    # data type: SuggestedBidSearchParameter
    oneof_schema_suggested_bid_search_parameter_validator: Optional[SuggestedBidSearchParameter] = None
    # data type: UrlSearchParameter
    oneof_schema_url_search_parameter_validator: Optional[UrlSearchParameter] = None
    actual_instance: Optional[Union[AuctionSegmentSearchParameter, CategorySearchParameter, CompetitionSearchParameter, DateRangeSearchParameter, DeviceSearchParameter, ExcludeAccountKeywordsSearchParameter, IdeaTextSearchParameter, ImpressionShareSearchParameter, LanguageSearchParameter, LocationSearchParameter, NetworkSearchParameter, QuerySearchParameter, SearchVolumeSearchParameter, SuggestedBidSearchParameter, UrlSearchParameter]] = None
    one_of_schemas: Set[str] = { "AuctionSegmentSearchParameter", "CategorySearchParameter", "CompetitionSearchParameter", "DateRangeSearchParameter", "DeviceSearchParameter", "ExcludeAccountKeywordsSearchParameter", "IdeaTextSearchParameter", "ImpressionShareSearchParameter", "LanguageSearchParameter", "LocationSearchParameter", "NetworkSearchParameter", "QuerySearchParameter", "SearchVolumeSearchParameter", "SuggestedBidSearchParameter", "UrlSearchParameter" }

    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):
        if v is None:
            return v

        instance = SearchParameter.model_construct()
        error_messages = []
        match = 0
        # validate data type: AuctionSegmentSearchParameter
        if not isinstance(v, AuctionSegmentSearchParameter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `AuctionSegmentSearchParameter`")
        else:
            match += 1
        # validate data type: CategorySearchParameter
        if not isinstance(v, CategorySearchParameter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `CategorySearchParameter`")
        else:
            match += 1
        # validate data type: CompetitionSearchParameter
        if not isinstance(v, CompetitionSearchParameter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `CompetitionSearchParameter`")
        else:
            match += 1
        # validate data type: DateRangeSearchParameter
        if not isinstance(v, DateRangeSearchParameter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `DateRangeSearchParameter`")
        else:
            match += 1
        # validate data type: DeviceSearchParameter
        if not isinstance(v, DeviceSearchParameter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `DeviceSearchParameter`")
        else:
            match += 1
        # validate data type: ExcludeAccountKeywordsSearchParameter
        if not isinstance(v, ExcludeAccountKeywordsSearchParameter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ExcludeAccountKeywordsSearchParameter`")
        else:
            match += 1
        # validate data type: IdeaTextSearchParameter
        if not isinstance(v, IdeaTextSearchParameter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IdeaTextSearchParameter`")
        else:
            match += 1
        # validate data type: ImpressionShareSearchParameter
        if not isinstance(v, ImpressionShareSearchParameter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ImpressionShareSearchParameter`")
        else:
            match += 1
        # validate data type: LanguageSearchParameter
        if not isinstance(v, LanguageSearchParameter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `LanguageSearchParameter`")
        else:
            match += 1
        # validate data type: LocationSearchParameter
        if not isinstance(v, LocationSearchParameter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `LocationSearchParameter`")
        else:
            match += 1
        # validate data type: NetworkSearchParameter
        if not isinstance(v, NetworkSearchParameter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `NetworkSearchParameter`")
        else:
            match += 1
        # validate data type: QuerySearchParameter
        if not isinstance(v, QuerySearchParameter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `QuerySearchParameter`")
        else:
            match += 1
        # validate data type: SearchVolumeSearchParameter
        if not isinstance(v, SearchVolumeSearchParameter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `SearchVolumeSearchParameter`")
        else:
            match += 1
        # validate data type: SuggestedBidSearchParameter
        if not isinstance(v, SuggestedBidSearchParameter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `SuggestedBidSearchParameter`")
        else:
            match += 1
        # validate data type: UrlSearchParameter
        if not isinstance(v, UrlSearchParameter):
            error_messages.append(f"Error! Input type `{type(v)}` is not `UrlSearchParameter`")
        else:
            match += 1
        if match > 1:
            # more than 1 match
            raise ValueError("Multiple matches found when setting `actual_instance` in SearchParameter with oneOf schemas: AuctionSegmentSearchParameter, CategorySearchParameter, CompetitionSearchParameter, DateRangeSearchParameter, DeviceSearchParameter, ExcludeAccountKeywordsSearchParameter, IdeaTextSearchParameter, ImpressionShareSearchParameter, LanguageSearchParameter, LocationSearchParameter, NetworkSearchParameter, QuerySearchParameter, SearchVolumeSearchParameter, SuggestedBidSearchParameter, UrlSearchParameter. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when setting `actual_instance` in SearchParameter with oneOf schemas: AuctionSegmentSearchParameter, CategorySearchParameter, CompetitionSearchParameter, DateRangeSearchParameter, DeviceSearchParameter, ExcludeAccountKeywordsSearchParameter, IdeaTextSearchParameter, ImpressionShareSearchParameter, LanguageSearchParameter, LocationSearchParameter, NetworkSearchParameter, QuerySearchParameter, SearchVolumeSearchParameter, SuggestedBidSearchParameter, UrlSearchParameter. 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: Optional[str]) -> Self:
        """Returns the object represented by the json string"""
        instance = cls.model_construct()
        if json_str is None:
            return instance

        error_messages = []
        match = 0

        # use oneOf discriminator to lookup the data type
        _data_type = json.loads(json_str).get("Type")
        if not _data_type:
            raise ValueError("Failed to lookup data type from the field `Type` in the input.")

		# check if data type is `AuctionSegmentSearchParameter`
        if _data_type == "AuctionSegmentSearchParameter":
            instance.actual_instance = AuctionSegmentSearchParameter.from_json(json_str)
            return instance
			
		# check if data type is `CategorySearchParameter`
        if _data_type == "CategorySearchParameter":
            instance.actual_instance = CategorySearchParameter.from_json(json_str)
            return instance
			
		# check if data type is `CompetitionSearchParameter`
        if _data_type == "CompetitionSearchParameter":
            instance.actual_instance = CompetitionSearchParameter.from_json(json_str)
            return instance
			
		# check if data type is `DateRangeSearchParameter`
        if _data_type == "DateRangeSearchParameter":
            instance.actual_instance = DateRangeSearchParameter.from_json(json_str)
            return instance
			
		# check if data type is `DeviceSearchParameter`
        if _data_type == "DeviceSearchParameter":
            instance.actual_instance = DeviceSearchParameter.from_json(json_str)
            return instance
			
		# check if data type is `ExcludeAccountKeywordsSearchParameter`
        if _data_type == "ExcludeAccountKeywordsSearchParameter":
            instance.actual_instance = ExcludeAccountKeywordsSearchParameter.from_json(json_str)
            return instance
			
		# check if data type is `IdeaTextSearchParameter`
        if _data_type == "IdeaTextSearchParameter":
            instance.actual_instance = IdeaTextSearchParameter.from_json(json_str)
            return instance
			
		# check if data type is `ImpressionShareSearchParameter`
        if _data_type == "ImpressionShareSearchParameter":
            instance.actual_instance = ImpressionShareSearchParameter.from_json(json_str)
            return instance
			
		# check if data type is `LanguageSearchParameter`
        if _data_type == "LanguageSearchParameter":
            instance.actual_instance = LanguageSearchParameter.from_json(json_str)
            return instance
			
		# check if data type is `LocationSearchParameter`
        if _data_type == "LocationSearchParameter":
            instance.actual_instance = LocationSearchParameter.from_json(json_str)
            return instance
			
		# check if data type is `NetworkSearchParameter`
        if _data_type == "NetworkSearchParameter":
            instance.actual_instance = NetworkSearchParameter.from_json(json_str)
            return instance
			
		# check if data type is `QuerySearchParameter`
        if _data_type == "QuerySearchParameter":
            instance.actual_instance = QuerySearchParameter.from_json(json_str)
            return instance
			
		# check if data type is `SearchVolumeSearchParameter`
        if _data_type == "SearchVolumeSearchParameter":
            instance.actual_instance = SearchVolumeSearchParameter.from_json(json_str)
            return instance
			
		# check if data type is `SuggestedBidSearchParameter`
        if _data_type == "SuggestedBidSearchParameter":
            instance.actual_instance = SuggestedBidSearchParameter.from_json(json_str)
            return instance
			
		# check if data type is `UrlSearchParameter`
        if _data_type == "UrlSearchParameter":
            instance.actual_instance = UrlSearchParameter.from_json(json_str)
            return instance
			

        # deserialize data into AuctionSegmentSearchParameter
        try:
            instance.actual_instance = AuctionSegmentSearchParameter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into CategorySearchParameter
        try:
            instance.actual_instance = CategorySearchParameter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into CompetitionSearchParameter
        try:
            instance.actual_instance = CompetitionSearchParameter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into DateRangeSearchParameter
        try:
            instance.actual_instance = DateRangeSearchParameter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into DeviceSearchParameter
        try:
            instance.actual_instance = DeviceSearchParameter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ExcludeAccountKeywordsSearchParameter
        try:
            instance.actual_instance = ExcludeAccountKeywordsSearchParameter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IdeaTextSearchParameter
        try:
            instance.actual_instance = IdeaTextSearchParameter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ImpressionShareSearchParameter
        try:
            instance.actual_instance = ImpressionShareSearchParameter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into LanguageSearchParameter
        try:
            instance.actual_instance = LanguageSearchParameter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into LocationSearchParameter
        try:
            instance.actual_instance = LocationSearchParameter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into NetworkSearchParameter
        try:
            instance.actual_instance = NetworkSearchParameter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into QuerySearchParameter
        try:
            instance.actual_instance = QuerySearchParameter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into SearchVolumeSearchParameter
        try:
            instance.actual_instance = SearchVolumeSearchParameter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into SuggestedBidSearchParameter
        try:
            instance.actual_instance = SuggestedBidSearchParameter.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into UrlSearchParameter
        try:
            instance.actual_instance = UrlSearchParameter.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 SearchParameter with oneOf schemas: AuctionSegmentSearchParameter, CategorySearchParameter, CompetitionSearchParameter, DateRangeSearchParameter, DeviceSearchParameter, ExcludeAccountKeywordsSearchParameter, IdeaTextSearchParameter, ImpressionShareSearchParameter, LanguageSearchParameter, LocationSearchParameter, NetworkSearchParameter, QuerySearchParameter, SearchVolumeSearchParameter, SuggestedBidSearchParameter, UrlSearchParameter. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when deserializing the JSON string into SearchParameter with oneOf schemas: AuctionSegmentSearchParameter, CategorySearchParameter, CompetitionSearchParameter, DateRangeSearchParameter, DeviceSearchParameter, ExcludeAccountKeywordsSearchParameter, IdeaTextSearchParameter, ImpressionShareSearchParameter, LanguageSearchParameter, LocationSearchParameter, NetworkSearchParameter, QuerySearchParameter, SearchVolumeSearchParameter, SuggestedBidSearchParameter, UrlSearchParameter. 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], AuctionSegmentSearchParameter, CategorySearchParameter, CompetitionSearchParameter, DateRangeSearchParameter, DeviceSearchParameter, ExcludeAccountKeywordsSearchParameter, IdeaTextSearchParameter, ImpressionShareSearchParameter, LanguageSearchParameter, LocationSearchParameter, NetworkSearchParameter, QuerySearchParameter, SearchVolumeSearchParameter, SuggestedBidSearchParameter, UrlSearchParameter]]:
        """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())

    def __getattr__(self, name):
        """Forward attribute access to actual_instance"""
        if self.actual_instance is not None and hasattr(self.actual_instance, name):
            return getattr(self.actual_instance, name)
        raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'")

    def __setattr__(self, name, value):
        """Forward attribute setting to actual_instance"""
        if name in ['actual_instance', 'oneof_schema_auction_segment_search_parameter_validator', 'oneof_schema_category_search_parameter_validator', 'oneof_schema_competition_search_parameter_validator', 'oneof_schema_date_range_search_parameter_validator', 'oneof_schema_device_search_parameter_validator', 'oneof_schema_exclude_account_keywords_search_parameter_validator', 'oneof_schema_idea_text_search_parameter_validator', 'oneof_schema_impression_share_search_parameter_validator', 'oneof_schema_language_search_parameter_validator', 'oneof_schema_location_search_parameter_validator', 'oneof_schema_network_search_parameter_validator', 'oneof_schema_query_search_parameter_validator', 'oneof_schema_search_volume_search_parameter_validator', 'oneof_schema_suggested_bid_search_parameter_validator', 'oneof_schema_url_search_parameter_validator', 'one_of_schemas', 'model_config', 'discriminator_value_class_map']:
            super().__setattr__(name, value)
        elif self.actual_instance is not None and hasattr(self.actual_instance, name):
            setattr(self.actual_instance, name, value)
        else:
            super().__setattr__(name, value)
