# 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 pprint
import re  # noqa: F401
import json

from datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union, Set
from openapi_client.models.campaign.ad_extension_status import AdExtensionStatus
from openapi_client.models.campaign.key_value_pair_ofstring_andstring import KeyValuePairOfstringAndstring
from openapi_client.models.campaign.schedule import Schedule
from typing_extensions import Self

class ReviewAdExtension(BaseModel):
    """
    ReviewAdExtension
    """ # noqa: E501
    is_exact: Optional[StrictBool] = Field(default=None, alias="IsExact")
    text: Optional[StrictStr] = Field(default=None, alias="Text")
    source: Optional[StrictStr] = Field(default=None, alias="Source")
    url: Optional[StrictStr] = Field(default=None, alias="Url")
    status: Optional[AdExtensionStatus] = Field(default=None, alias="Status")
    scheduling: Optional[Schedule] = Field(default=None, alias="Scheduling")
    device_preference: Optional[StrictStr] = Field(default=None, alias="DevicePreference")
    id: Optional[StrictStr] = Field(default=None, alias="Id")
    type: Optional[StrictStr] = Field(default='ReviewAdExtension', alias="Type")
    version: Optional[StrictInt] = Field(default=None, alias="Version")
    forward_compatibility_map: Optional[List[Optional[KeyValuePairOfstringAndstring]]] = Field(default=None, alias="ForwardCompatibilityMap")
    __properties: ClassVar[List[str]] = ["IsExact", "Text", "Source", "Url", "Status", "Scheduling", "DevicePreference", "Id", "Type", "Version", "ForwardCompatibilityMap"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )
	
    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())
	
    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of ReviewAdExtension 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.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of scheduling
        if self.scheduling:
            _dict['Scheduling'] = self.scheduling.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in forward_compatibility_map (list)
        _items = []
        if self.forward_compatibility_map:
            for _item_forward_compatibility_map in self.forward_compatibility_map:
                if _item_forward_compatibility_map:
                    _items.append(_item_forward_compatibility_map.to_dict())
            _dict['ForwardCompatibilityMap'] = _items
        # set to None if is_exact (nullable) is None
        # and model_fields_set contains the field
        if self.is_exact is None and "is_exact" in self.model_fields_set:
            _dict['IsExact'] = None

        # set to None if text (nullable) is None
        # and model_fields_set contains the field
        if self.text is None and "text" in self.model_fields_set:
            _dict['Text'] = None

        # set to None if source (nullable) is None
        # and model_fields_set contains the field
        if self.source is None and "source" in self.model_fields_set:
            _dict['Source'] = None

        # set to None if url (nullable) is None
        # and model_fields_set contains the field
        if self.url is None and "url" in self.model_fields_set:
            _dict['Url'] = None

        # set to None if status (nullable) is None
        # and model_fields_set contains the field
        if self.status is None and "status" in self.model_fields_set:
            _dict['Status'] = None

        # set to None if scheduling (nullable) is None
        # and model_fields_set contains the field
        if self.scheduling is None and "scheduling" in self.model_fields_set:
            _dict['Scheduling'] = None

        # set to None if device_preference (nullable) is None
        # and model_fields_set contains the field
        if self.device_preference is None and "device_preference" in self.model_fields_set:
            _dict['DevicePreference'] = None

        # set to None if id (nullable) is None
        # and model_fields_set contains the field
        if self.id is None and "id" in self.model_fields_set:
            _dict['Id'] = None

        # 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

        # set to None if version (nullable) is None
        # and model_fields_set contains the field
        if self.version is None and "version" in self.model_fields_set:
            _dict['Version'] = None

        # set to None if forward_compatibility_map (nullable) is None
        # and model_fields_set contains the field
        if self.forward_compatibility_map is None and "forward_compatibility_map" in self.model_fields_set:
            _dict['ForwardCompatibilityMap'] = None

        return _dict

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

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

        _obj = cls.model_validate({
            "IsExact": obj.get("IsExact") if obj.get("IsExact") is not None else None,
                        "Text": obj.get("Text") if obj.get("Text") is not None else None,
                        "Source": obj.get("Source") if obj.get("Source") is not None else None,
                        "Url": obj.get("Url") if obj.get("Url") is not None else None,
                        "Status": obj.get("Status") if obj.get("Status") is not None else None,
                        "Scheduling": Schedule.from_dict(obj["Scheduling"]) if obj.get("Scheduling") is not None else None,
                        "DevicePreference": obj.get("DevicePreference") if obj.get("DevicePreference") is not None else None,
                        "Id": obj.get("Id") if obj.get("Id") is not None else None,
                        "Type": obj.get("Type") if obj.get("Type") is not None else 'ReviewAdExtension',
                        "Version": obj.get("Version") if obj.get("Version") is not None else None,
                        "ForwardCompatibilityMap": [KeyValuePairOfstringAndstring.from_dict(_item) for _item in obj["ForwardCompatibilityMap"]] if obj.get("ForwardCompatibilityMap") is not None else None
        })
        return _obj
