# 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_editorial_status import AdEditorialStatus
from openapi_client.models.campaign.ad_status import AdStatus
from openapi_client.models.campaign.app_url import AppUrl
from openapi_client.models.campaign.custom_parameters import CustomParameters
from openapi_client.models.campaign.key_value_pair_ofstring_andstring import KeyValuePairOfstringAndstring
from typing_extensions import Self

class DynamicSearchAd(BaseModel):
    """
    DynamicSearchAd
    """ # noqa: E501
    text: Optional[StrictStr] = Field(default=None, alias="Text")
    text_part2: Optional[StrictStr] = Field(default=None, alias="TextPart2")
    path1: Optional[StrictStr] = Field(default=None, alias="Path1")
    path2: Optional[StrictStr] = Field(default=None, alias="Path2")
    id: Optional[StrictStr] = Field(default=None, alias="Id")
    type: Optional[StrictStr] = Field(default='DynamicSearch', alias="Type")
    status: Optional[AdStatus] = Field(default=None, alias="Status")
    editorial_status: Optional[AdEditorialStatus] = Field(default=None, alias="EditorialStatus")
    device_preference: Optional[StrictStr] = Field(default=None, alias="DevicePreference")
    ad_format_preference: Optional[StrictStr] = Field(default=None, alias="AdFormatPreference")
    tracking_url_template: Optional[StrictStr] = Field(default=None, alias="TrackingUrlTemplate")
    final_url_suffix: Optional[StrictStr] = Field(default=None, alias="FinalUrlSuffix")
    url_custom_parameters: Optional[CustomParameters] = Field(default=None, alias="UrlCustomParameters")
    final_urls: Optional[List[StrictStr]] = Field(default=None, alias="FinalUrls")
    final_mobile_urls: Optional[List[StrictStr]] = Field(default=None, alias="FinalMobileUrls")
    final_app_urls: Optional[List[Optional[AppUrl]]] = Field(default=None, alias="FinalAppUrls")
    forward_compatibility_map: Optional[List[Optional[KeyValuePairOfstringAndstring]]] = Field(default=None, alias="ForwardCompatibilityMap")
    __properties: ClassVar[List[str]] = ["Text", "TextPart2", "Path1", "Path2", "Id", "Type", "Status", "EditorialStatus", "DevicePreference", "AdFormatPreference", "TrackingUrlTemplate", "FinalUrlSuffix", "UrlCustomParameters", "FinalUrls", "FinalMobileUrls", "FinalAppUrls", "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 DynamicSearchAd 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 url_custom_parameters
        if self.url_custom_parameters:
            _dict['UrlCustomParameters'] = self.url_custom_parameters.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in final_app_urls (list)
        _items = []
        if self.final_app_urls:
            for _item_final_app_urls in self.final_app_urls:
                if _item_final_app_urls:
                    _items.append(_item_final_app_urls.to_dict())
            _dict['FinalAppUrls'] = _items
        # 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 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 text_part2 (nullable) is None
        # and model_fields_set contains the field
        if self.text_part2 is None and "text_part2" in self.model_fields_set:
            _dict['TextPart2'] = None

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

        # set to None if path2 (nullable) is None
        # and model_fields_set contains the field
        if self.path2 is None and "path2" in self.model_fields_set:
            _dict['Path2'] = 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 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 editorial_status (nullable) is None
        # and model_fields_set contains the field
        if self.editorial_status is None and "editorial_status" in self.model_fields_set:
            _dict['EditorialStatus'] = 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 ad_format_preference (nullable) is None
        # and model_fields_set contains the field
        if self.ad_format_preference is None and "ad_format_preference" in self.model_fields_set:
            _dict['AdFormatPreference'] = None

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

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

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

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

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

        # set to None if final_app_urls (nullable) is None
        # and model_fields_set contains the field
        if self.final_app_urls is None and "final_app_urls" in self.model_fields_set:
            _dict['FinalAppUrls'] = 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 DynamicSearchAd from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate({
            "Text": obj.get("Text") if obj.get("Text") is not None else None,
                        "TextPart2": obj.get("TextPart2") if obj.get("TextPart2") is not None else None,
                        "Path1": obj.get("Path1") if obj.get("Path1") is not None else None,
                        "Path2": obj.get("Path2") if obj.get("Path2") 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 'DynamicSearch',
                        "Status": obj.get("Status") if obj.get("Status") is not None else None,
                        "EditorialStatus": obj.get("EditorialStatus") if obj.get("EditorialStatus") is not None else None,
                        "DevicePreference": obj.get("DevicePreference") if obj.get("DevicePreference") is not None else None,
                        "AdFormatPreference": obj.get("AdFormatPreference") if obj.get("AdFormatPreference") is not None else None,
                        "TrackingUrlTemplate": obj.get("TrackingUrlTemplate") if obj.get("TrackingUrlTemplate") is not None else None,
                        "FinalUrlSuffix": obj.get("FinalUrlSuffix") if obj.get("FinalUrlSuffix") is not None else None,
                        "UrlCustomParameters": CustomParameters.from_dict(obj["UrlCustomParameters"]) if obj.get("UrlCustomParameters") is not None else None,
                        "FinalUrls": obj.get("FinalUrls"),
                        "FinalMobileUrls": obj.get("FinalMobileUrls"),
                        "FinalAppUrls": [AppUrl.from_dict(_item) for _item in obj["FinalAppUrls"]] if obj.get("FinalAppUrls") 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
