# coding: utf-8

"""
    CampaignManagementService

    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.campaign.account_negative_keyword_list import AccountNegativeKeywordList
from openapi_client.models.campaign.account_placement_exclusion_list import AccountPlacementExclusionList
from openapi_client.models.campaign.account_placement_inclusion_list import AccountPlacementInclusionList
from openapi_client.models.campaign.brand_list import BrandList
from openapi_client.models.campaign.key_value_pair_ofstring_andstring import KeyValuePairOfstringAndstring
from openapi_client.models.campaign.negative_keyword_list import NegativeKeywordList
from openapi_client.models.campaign.placement_exclusion_list import PlacementExclusionList
from pydantic import StrictStr, Field
from typing import Union, List, Set, Optional, Dict
from typing_extensions import Literal, Self

SharedList_ONE_OF_SCHEMAS = ["AccountNegativeKeywordList", "AccountPlacementExclusionList", "AccountPlacementInclusionList", "BrandList", "NegativeKeywordList", "PlacementExclusionList"]

class SharedList(BaseModel):
    """
    SharedList
    """
    # data type: AccountNegativeKeywordList
    oneof_schema_account_negative_keyword_list_validator: Optional[AccountNegativeKeywordList] = None
    # data type: AccountPlacementExclusionList
    oneof_schema_account_placement_exclusion_list_validator: Optional[AccountPlacementExclusionList] = None
    # data type: AccountPlacementInclusionList
    oneof_schema_account_placement_inclusion_list_validator: Optional[AccountPlacementInclusionList] = None
    # data type: BrandList
    oneof_schema_brand_list_validator: Optional[BrandList] = None
    # data type: NegativeKeywordList
    oneof_schema_negative_keyword_list_validator: Optional[NegativeKeywordList] = None
    # data type: PlacementExclusionList
    oneof_schema_placement_exclusion_list_validator: Optional[PlacementExclusionList] = None
    actual_instance: Optional[Union[AccountNegativeKeywordList, AccountPlacementExclusionList, AccountPlacementInclusionList, BrandList, NegativeKeywordList, PlacementExclusionList]] = None
    one_of_schemas: Set[str] = { "AccountNegativeKeywordList", "AccountPlacementExclusionList", "AccountPlacementInclusionList", "BrandList", "NegativeKeywordList", "PlacementExclusionList" }

    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 = SharedList.model_construct()
        error_messages = []
        match = 0
        # validate data type: AccountNegativeKeywordList
        if not isinstance(v, AccountNegativeKeywordList):
            error_messages.append(f"Error! Input type `{type(v)}` is not `AccountNegativeKeywordList`")
        else:
            match += 1
        # validate data type: AccountPlacementExclusionList
        if not isinstance(v, AccountPlacementExclusionList):
            error_messages.append(f"Error! Input type `{type(v)}` is not `AccountPlacementExclusionList`")
        else:
            match += 1
        # validate data type: AccountPlacementInclusionList
        if not isinstance(v, AccountPlacementInclusionList):
            error_messages.append(f"Error! Input type `{type(v)}` is not `AccountPlacementInclusionList`")
        else:
            match += 1
        # validate data type: BrandList
        if not isinstance(v, BrandList):
            error_messages.append(f"Error! Input type `{type(v)}` is not `BrandList`")
        else:
            match += 1
        # validate data type: NegativeKeywordList
        if not isinstance(v, NegativeKeywordList):
            error_messages.append(f"Error! Input type `{type(v)}` is not `NegativeKeywordList`")
        else:
            match += 1
        # validate data type: PlacementExclusionList
        if not isinstance(v, PlacementExclusionList):
            error_messages.append(f"Error! Input type `{type(v)}` is not `PlacementExclusionList`")
        else:
            match += 1
        if match > 1:
            # more than 1 match
            raise ValueError("Multiple matches found when setting `actual_instance` in SharedList with oneOf schemas: AccountNegativeKeywordList, AccountPlacementExclusionList, AccountPlacementInclusionList, BrandList, NegativeKeywordList, PlacementExclusionList. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when setting `actual_instance` in SharedList with oneOf schemas: AccountNegativeKeywordList, AccountPlacementExclusionList, AccountPlacementInclusionList, BrandList, NegativeKeywordList, PlacementExclusionList. 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 `AccountNegativeKeywordList`
        if _data_type == "AccountNegativeKeywordList":
            instance.actual_instance = AccountNegativeKeywordList.from_json(json_str)
            return instance
			
		# check if data type is `AccountPlacementExclusionList`
        if _data_type == "AccountPlacementExclusionList":
            instance.actual_instance = AccountPlacementExclusionList.from_json(json_str)
            return instance
			
		# check if data type is `AccountPlacementInclusionList`
        if _data_type == "AccountPlacementInclusionList":
            instance.actual_instance = AccountPlacementInclusionList.from_json(json_str)
            return instance
			
		# check if data type is `BrandList`
        if _data_type == "BrandList":
            instance.actual_instance = BrandList.from_json(json_str)
            return instance
			
		# check if data type is `NegativeKeywordList`
        if _data_type == "NegativeKeywordList":
            instance.actual_instance = NegativeKeywordList.from_json(json_str)
            return instance
			
		# check if data type is `PlacementExclusionList`
        if _data_type == "PlacementExclusionList":
            instance.actual_instance = PlacementExclusionList.from_json(json_str)
            return instance
			

        # deserialize data into AccountNegativeKeywordList
        try:
            instance.actual_instance = AccountNegativeKeywordList.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into AccountPlacementExclusionList
        try:
            instance.actual_instance = AccountPlacementExclusionList.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into AccountPlacementInclusionList
        try:
            instance.actual_instance = AccountPlacementInclusionList.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into BrandList
        try:
            instance.actual_instance = BrandList.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into NegativeKeywordList
        try:
            instance.actual_instance = NegativeKeywordList.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into PlacementExclusionList
        try:
            instance.actual_instance = PlacementExclusionList.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 SharedList with oneOf schemas: AccountNegativeKeywordList, AccountPlacementExclusionList, AccountPlacementInclusionList, BrandList, NegativeKeywordList, PlacementExclusionList. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when deserializing the JSON string into SharedList with oneOf schemas: AccountNegativeKeywordList, AccountPlacementExclusionList, AccountPlacementInclusionList, BrandList, NegativeKeywordList, PlacementExclusionList. 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], AccountNegativeKeywordList, AccountPlacementExclusionList, AccountPlacementInclusionList, BrandList, NegativeKeywordList, PlacementExclusionList]]:
        """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_account_negative_keyword_list_validator', 'oneof_schema_account_placement_exclusion_list_validator', 'oneof_schema_account_placement_inclusion_list_validator', 'oneof_schema_brand_list_validator', 'oneof_schema_negative_keyword_list_validator', 'oneof_schema_placement_exclusion_list_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)
