# 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 AudienceGroupDimension(BaseModel):
    """
    AudienceGroupDimension
    """

    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 = [
                ('AgeDimension', 'Age'),
                ('AudienceDimension', 'Audience'),
                ('GenderDimension', 'Gender'),
                ('ProfileDimension', 'Profile'),
                ('AgeDimension', 'AgeDimension'),
                ('AudienceDimension', 'AudienceDimension'),
                ('GenderDimension', 'GenderDimension'),
                ('ProfileDimension', 'ProfileDimension'),
            ]
            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 AudienceGroupDimension 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 AudienceGroupDimension 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 == "Age":
            from openapi_client.models.campaign.age_dimension import AgeDimension
            return AgeDimension.from_dict(obj)
        
        if type == "Audience":
            from openapi_client.models.campaign.audience_dimension import AudienceDimension
            return AudienceDimension.from_dict(obj)
        
        if type == "Gender":
            from openapi_client.models.campaign.gender_dimension import GenderDimension
            return GenderDimension.from_dict(obj)
        
        if type == "Profile":
            from openapi_client.models.campaign.profile_dimension import ProfileDimension
            return ProfileDimension.from_dict(obj)
        
        if type == "AgeDimension":
            from openapi_client.models.campaign.age_dimension import AgeDimension
            return AgeDimension.from_dict(obj)
        
        if type == "AudienceDimension":
            from openapi_client.models.campaign.audience_dimension import AudienceDimension
            return AudienceDimension.from_dict(obj)
        
        if type == "GenderDimension":
            from openapi_client.models.campaign.gender_dimension import GenderDimension
            return GenderDimension.from_dict(obj)
        
        if type == "ProfileDimension":
            from openapi_client.models.campaign.profile_dimension import ProfileDimension
            return ProfileDimension.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
