# 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 pydantic import StrictStr, Field
from typing import Union, List, Set, Optional, Dict
from typing_extensions import Literal, Self

class Setting(BaseModel):
    """
    Setting
    """

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )

    def __init__(self, **kwargs):
        if 'type' not in kwargs and 'Type' not in kwargs:
            class_name = self.__class__.__name__
            type_mapping = [
                ('AISearchSetting', 'AISearchSetting'),
                ('AppSetting', 'AppSetting'),
                ('BaseDomainSetting', 'BaseDomainSetting'),
                ('CallToActionSetting', 'CallToActionSetting'),
                ('CoOpSetting', 'CoOpSetting'),
                ('DisclaimerSetting', 'DisclaimerSetting'),
                ('DynamicFeedSetting', 'DynamicFeedSetting'),
                ('DynamicSearchAdsSetting', 'DynamicSearchAdsSetting'),
                ('HotelSetting', 'HotelSetting'),
                ('NewCustomerAcquisitionGoalSetting', 'NewCustomerAcquisitionGoalSetting'),
                ('PerformanceMaxSetting', 'PerformanceMaxSetting'),
                ('ResponsiveSearchAdsSetting', 'ResponsiveSearchAdsSetting'),
                ('ShoppingSetting', 'ShoppingSetting'),
                ('TargetSetting', 'TargetSetting'),
                ('ThirdPartyMeasurementSetting', 'ThirdPartyMeasurementSetting'),
                ('VanityPharmaSetting', 'VanityPharmaSetting'),
                ('VerifiedTrackingSetting', 'VerifiedTrackingSetting'),
            ]
            for key, value in type_mapping:
                if class_name == key:
                    kwargs['type'] = value
                    break
        super().__init__(**kwargs)

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: Optional[str]) -> Self:
        """Create an instance of Setting from a JSON string"""
        return cls.from_dict(json.loads(json_str))
    
    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias."""
        excluded_fields: Set[str] = set([])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        
        # set to None if type (nullable) is None and model_fields_set contains the field
        if self.type is None and "type" in self.model_fields_set:
            _dict['Type'] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of Setting from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        # Try to determine the specific media type from the Type field
        type = obj.get("Type")
        
        # Import here to avoid circular imports
        if type == "AISearchSetting":
            from openapi_client.models.campaign.ai_search_setting import AISearchSetting
            return AISearchSetting.from_dict(obj)
        
        if type == "AppSetting":
            from openapi_client.models.campaign.app_setting import AppSetting
            return AppSetting.from_dict(obj)
        
        if type == "BaseDomainSetting":
            from openapi_client.models.campaign.base_domain_setting import BaseDomainSetting
            return BaseDomainSetting.from_dict(obj)
        
        if type == "CallToActionSetting":
            from openapi_client.models.campaign.call_to_action_setting import CallToActionSetting
            return CallToActionSetting.from_dict(obj)
        
        if type == "CoOpSetting":
            from openapi_client.models.campaign.co_op_setting import CoOpSetting
            return CoOpSetting.from_dict(obj)
        
        if type == "DisclaimerSetting":
            from openapi_client.models.campaign.disclaimer_setting import DisclaimerSetting
            return DisclaimerSetting.from_dict(obj)
        
        if type == "DynamicFeedSetting":
            from openapi_client.models.campaign.dynamic_feed_setting import DynamicFeedSetting
            return DynamicFeedSetting.from_dict(obj)
        
        if type == "DynamicSearchAdsSetting":
            from openapi_client.models.campaign.dynamic_search_ads_setting import DynamicSearchAdsSetting
            return DynamicSearchAdsSetting.from_dict(obj)
        
        if type == "HotelSetting":
            from openapi_client.models.campaign.hotel_setting import HotelSetting
            return HotelSetting.from_dict(obj)
        
        if type == "NewCustomerAcquisitionGoalSetting":
            from openapi_client.models.campaign.new_customer_acquisition_goal_setting import NewCustomerAcquisitionGoalSetting
            return NewCustomerAcquisitionGoalSetting.from_dict(obj)
        
        if type == "PerformanceMaxSetting":
            from openapi_client.models.campaign.performance_max_setting import PerformanceMaxSetting
            return PerformanceMaxSetting.from_dict(obj)
        
        if type == "ResponsiveSearchAdsSetting":
            from openapi_client.models.campaign.responsive_search_ads_setting import ResponsiveSearchAdsSetting
            return ResponsiveSearchAdsSetting.from_dict(obj)
        
        if type == "ShoppingSetting":
            from openapi_client.models.campaign.shopping_setting import ShoppingSetting
            return ShoppingSetting.from_dict(obj)
        
        if type == "TargetSetting":
            from openapi_client.models.campaign.target_setting import TargetSetting
            return TargetSetting.from_dict(obj)
        
        if type == "ThirdPartyMeasurementSetting":
            from openapi_client.models.campaign.third_party_measurement_setting import ThirdPartyMeasurementSetting
            return ThirdPartyMeasurementSetting.from_dict(obj)
        
        if type == "VanityPharmaSetting":
            from openapi_client.models.campaign.vanity_pharma_setting import VanityPharmaSetting
            return VanityPharmaSetting.from_dict(obj)
        
        if type == "VerifiedTrackingSetting":
            from openapi_client.models.campaign.verified_tracking_setting import VerifiedTrackingSetting
            return VerifiedTrackingSetting.from_dict(obj)
        
        
        # Fallback to base class
        _obj = cls.model_validate({
            "Type": obj.get("Type") if obj.get("Type") is not None else None
        })
        return _obj
