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

    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 = [
                ('AgeCriterion', 'AgeCriterion'),
                ('AudienceCriterion', 'AudienceCriterion'),
                ('DayTimeCriterion', 'DayTimeCriterion'),
                ('DealCriterion', 'DealCriterion'),
                ('DeviceCriterion', 'DeviceCriterion'),
                ('GenderCriterion', 'GenderCriterion'),
                ('GenreCriterion', 'GenreCriterion'),
                ('HotelAdvanceBookingWindowCriterion', 'HotelAdvanceBookingWindowCriterion'),
                ('HotelCheckInDateCriterion', 'HotelCheckInDateCriterion'),
                ('HotelCheckInDayCriterion', 'HotelCheckInDayCriterion'),
                ('HotelDateSelectionTypeCriterion', 'HotelDateSelectionTypeCriterion'),
                ('HotelGroup', 'HotelGroup'),
                ('HotelLengthOfStayCriterion', 'HotelLengthOfStayCriterion'),
                ('LocationCriterion', 'LocationCriterion'),
                ('LocationIntentCriterion', 'LocationIntentCriterion'),
                ('PlacementCriterion', 'PlacementCriterion'),
                ('ProductPartition', 'ProductPartition'),
                ('ProductScope', 'ProductScope'),
                ('ProfileCriterion', 'ProfileCriterion'),
                ('RadiusCriterion', 'RadiusCriterion'),
                ('StoreCriterion', 'StoreCriterion'),
                ('TopicCriterion', 'TopicCriterion'),
                ('Webpage', 'Webpage'),
            ]
            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 Criterion 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 Criterion 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 == "AgeCriterion":
            from openapi_client.models.campaign.age_criterion import AgeCriterion
            return AgeCriterion.from_dict(obj)
        
        if type == "AudienceCriterion":
            from openapi_client.models.campaign.audience_criterion import AudienceCriterion
            return AudienceCriterion.from_dict(obj)
        
        if type == "DayTimeCriterion":
            from openapi_client.models.campaign.day_time_criterion import DayTimeCriterion
            return DayTimeCriterion.from_dict(obj)
        
        if type == "DealCriterion":
            from openapi_client.models.campaign.deal_criterion import DealCriterion
            return DealCriterion.from_dict(obj)
        
        if type == "DeviceCriterion":
            from openapi_client.models.campaign.device_criterion import DeviceCriterion
            return DeviceCriterion.from_dict(obj)
        
        if type == "GenderCriterion":
            from openapi_client.models.campaign.gender_criterion import GenderCriterion
            return GenderCriterion.from_dict(obj)
        
        if type == "GenreCriterion":
            from openapi_client.models.campaign.genre_criterion import GenreCriterion
            return GenreCriterion.from_dict(obj)
        
        if type == "HotelAdvanceBookingWindowCriterion":
            from openapi_client.models.campaign.hotel_advance_booking_window_criterion import HotelAdvanceBookingWindowCriterion
            return HotelAdvanceBookingWindowCriterion.from_dict(obj)
        
        if type == "HotelCheckInDateCriterion":
            from openapi_client.models.campaign.hotel_check_in_date_criterion import HotelCheckInDateCriterion
            return HotelCheckInDateCriterion.from_dict(obj)
        
        if type == "HotelCheckInDayCriterion":
            from openapi_client.models.campaign.hotel_check_in_day_criterion import HotelCheckInDayCriterion
            return HotelCheckInDayCriterion.from_dict(obj)
        
        if type == "HotelDateSelectionTypeCriterion":
            from openapi_client.models.campaign.hotel_date_selection_type_criterion import HotelDateSelectionTypeCriterion
            return HotelDateSelectionTypeCriterion.from_dict(obj)
        
        if type == "HotelGroup":
            from openapi_client.models.campaign.hotel_group import HotelGroup
            return HotelGroup.from_dict(obj)
        
        if type == "HotelLengthOfStayCriterion":
            from openapi_client.models.campaign.hotel_length_of_stay_criterion import HotelLengthOfStayCriterion
            return HotelLengthOfStayCriterion.from_dict(obj)
        
        if type == "LocationCriterion":
            from openapi_client.models.campaign.location_criterion import LocationCriterion
            return LocationCriterion.from_dict(obj)
        
        if type == "LocationIntentCriterion":
            from openapi_client.models.campaign.location_intent_criterion import LocationIntentCriterion
            return LocationIntentCriterion.from_dict(obj)
        
        if type == "PlacementCriterion":
            from openapi_client.models.campaign.placement_criterion import PlacementCriterion
            return PlacementCriterion.from_dict(obj)
        
        if type == "ProductPartition":
            from openapi_client.models.campaign.product_partition import ProductPartition
            return ProductPartition.from_dict(obj)
        
        if type == "ProductScope":
            from openapi_client.models.campaign.product_scope import ProductScope
            return ProductScope.from_dict(obj)
        
        if type == "ProfileCriterion":
            from openapi_client.models.campaign.profile_criterion import ProfileCriterion
            return ProfileCriterion.from_dict(obj)
        
        if type == "RadiusCriterion":
            from openapi_client.models.campaign.radius_criterion import RadiusCriterion
            return RadiusCriterion.from_dict(obj)
        
        if type == "StoreCriterion":
            from openapi_client.models.campaign.store_criterion import StoreCriterion
            return StoreCriterion.from_dict(obj)
        
        if type == "TopicCriterion":
            from openapi_client.models.campaign.topic_criterion import TopicCriterion
            return TopicCriterion.from_dict(obj)
        
        if type == "Webpage":
            from openapi_client.models.campaign.webpage import Webpage
            return Webpage.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
