# 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_group_privacy_status import AdGroupPrivacyStatus
from openapi_client.models.campaign.ad_group_status import AdGroupStatus
from openapi_client.models.campaign.ad_rotation import AdRotation
from openapi_client.models.campaign.bid import Bid
from openapi_client.models.campaign.bidding_scheme import BiddingScheme
from openapi_client.models.campaign.custom_parameters import CustomParameters
from openapi_client.models.campaign.frequency_cap_settings import FrequencyCapSettings
from openapi_client.models.campaign.key_value_pair_ofstring_andstring import KeyValuePairOfstringAndstring
from openapi_client.models.campaign.model_date import ModelDate
from openapi_client.models.campaign.network import Network
from openapi_client.models.campaign.rate_bid import RateBid
from openapi_client.models.campaign.setting import Setting
from typing_extensions import Self

class AdGroup(BaseModel):
    """
    AdGroup
    """ # noqa: E501
    id: Optional[StrictStr] = Field(default=None, alias="Id")
    name: Optional[StrictStr] = Field(default=None, alias="Name")
    start_date: Optional[ModelDate] = Field(default=None, alias="StartDate")
    end_date: Optional[ModelDate] = Field(default=None, alias="EndDate")
    language: Optional[StrictStr] = Field(default=None, alias="Language")
    status: Optional[AdGroupStatus] = Field(default=None, alias="Status")
    privacy_status: Optional[AdGroupPrivacyStatus] = Field(default=None, alias="PrivacyStatus")
    cpc_bid: Optional[Bid] = Field(default=None, alias="CpcBid")
    network: Optional[Network] = Field(default=None, alias="Network")
    ad_rotation: Optional[AdRotation] = Field(default=None, alias="AdRotation")
    audience_ads_bid_adjustment: Optional[StrictInt] = Field(default=None, alias="AudienceAdsBidAdjustment")
    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")
    bidding_scheme: Optional[BiddingScheme] = Field(default=None, alias="BiddingScheme")
    settings: Optional[List[Optional[Setting]]] = Field(default=None, alias="Settings")
    ad_schedule_use_searcher_time_zone: Optional[StrictBool] = Field(default=None, alias="AdScheduleUseSearcherTimeZone")
    ad_group_type: Optional[StrictStr] = Field(default=None, alias="AdGroupType")
    cpv_bid: Optional[Bid] = Field(default=None, alias="CpvBid")
    cpm_bid: Optional[Bid] = Field(default=None, alias="CpmBid")
    mcpa_bid: Optional[Bid] = Field(default=None, alias="McpaBid")
    multimedia_ads_bid_adjustment: Optional[StrictInt] = Field(default=None, alias="MultimediaAdsBidAdjustment")
    commission_rate: Optional[RateBid] = Field(default=None, alias="CommissionRate")
    percent_cpc_bid: Optional[RateBid] = Field(default=None, alias="PercentCpcBid")
    use_optimized_targeting: Optional[StrictBool] = Field(default=None, alias="UseOptimizedTargeting")
    use_predictive_targeting: Optional[StrictBool] = Field(default=None, alias="UsePredictiveTargeting")
    frequency_cap_settings: Optional[List[Optional[FrequencyCapSettings]]] = Field(default=None, alias="FrequencyCapSettings")
    forward_compatibility_map: Optional[List[Optional[KeyValuePairOfstringAndstring]]] = Field(default=None, alias="ForwardCompatibilityMap")
    __properties: ClassVar[List[str]] = ["Id", "Name", "StartDate", "EndDate", "Language", "Status", "PrivacyStatus", "CpcBid", "Network", "AdRotation", "AudienceAdsBidAdjustment", "TrackingUrlTemplate", "FinalUrlSuffix", "UrlCustomParameters", "BiddingScheme", "Settings", "AdScheduleUseSearcherTimeZone", "AdGroupType", "CpvBid", "CpmBid", "McpaBid", "MultimediaAdsBidAdjustment", "CommissionRate", "PercentCpcBid", "UseOptimizedTargeting", "UsePredictiveTargeting", "FrequencyCapSettings", "ForwardCompatibilityMap"]

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

    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 start_date
        if self.start_date:
            _dict['StartDate'] = self.start_date.to_dict()
        # override the default output from pydantic by calling `to_dict()` of end_date
        if self.end_date:
            _dict['EndDate'] = self.end_date.to_dict()
        # override the default output from pydantic by calling `to_dict()` of cpc_bid
        if self.cpc_bid:
            _dict['CpcBid'] = self.cpc_bid.to_dict()
        # override the default output from pydantic by calling `to_dict()` of ad_rotation
        if self.ad_rotation:
            _dict['AdRotation'] = self.ad_rotation.to_dict()
        # 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 bidding_scheme
        if self.bidding_scheme:
            _dict['BiddingScheme'] = self.bidding_scheme.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in settings (list)
        _items = []
        if self.settings:
            for _item_settings in self.settings:
                if _item_settings:
                    _items.append(_item_settings.to_dict())
            _dict['Settings'] = _items
        # override the default output from pydantic by calling `to_dict()` of cpv_bid
        if self.cpv_bid:
            _dict['CpvBid'] = self.cpv_bid.to_dict()
        # override the default output from pydantic by calling `to_dict()` of cpm_bid
        if self.cpm_bid:
            _dict['CpmBid'] = self.cpm_bid.to_dict()
        # override the default output from pydantic by calling `to_dict()` of mcpa_bid
        if self.mcpa_bid:
            _dict['McpaBid'] = self.mcpa_bid.to_dict()
        # override the default output from pydantic by calling `to_dict()` of commission_rate
        if self.commission_rate:
            _dict['CommissionRate'] = self.commission_rate.to_dict()
        # override the default output from pydantic by calling `to_dict()` of percent_cpc_bid
        if self.percent_cpc_bid:
            _dict['PercentCpcBid'] = self.percent_cpc_bid.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in frequency_cap_settings (list)
        _items = []
        if self.frequency_cap_settings:
            for _item_frequency_cap_settings in self.frequency_cap_settings:
                if _item_frequency_cap_settings:
                    _items.append(_item_frequency_cap_settings.to_dict())
            _dict['FrequencyCapSettings'] = _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 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 name (nullable) is None
        # and model_fields_set contains the field
        if self.name is None and "name" in self.model_fields_set:
            _dict['Name'] = None

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

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

        # set to None if language (nullable) is None
        # and model_fields_set contains the field
        if self.language is None and "language" in self.model_fields_set:
            _dict['Language'] = 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 privacy_status (nullable) is None
        # and model_fields_set contains the field
        if self.privacy_status is None and "privacy_status" in self.model_fields_set:
            _dict['PrivacyStatus'] = None

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

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

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

        # set to None if audience_ads_bid_adjustment (nullable) is None
        # and model_fields_set contains the field
        if self.audience_ads_bid_adjustment is None and "audience_ads_bid_adjustment" in self.model_fields_set:
            _dict['AudienceAdsBidAdjustment'] = 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 bidding_scheme (nullable) is None
        # and model_fields_set contains the field
        if self.bidding_scheme is None and "bidding_scheme" in self.model_fields_set:
            _dict['BiddingScheme'] = None

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

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

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

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

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

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

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

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

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

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

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

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

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

        _obj = cls.model_validate({
            "Id": obj.get("Id") if obj.get("Id") is not None else None,
                        "Name": obj.get("Name") if obj.get("Name") is not None else None,
                        "StartDate": ModelDate.from_dict(obj["StartDate"]) if obj.get("StartDate") is not None else None,
                        "EndDate": ModelDate.from_dict(obj["EndDate"]) if obj.get("EndDate") is not None else None,
                        "Language": obj.get("Language") if obj.get("Language") is not None else None,
                        "Status": obj.get("Status") if obj.get("Status") is not None else None,
                        "PrivacyStatus": obj.get("PrivacyStatus") if obj.get("PrivacyStatus") is not None else None,
                        "CpcBid": Bid.from_dict(obj["CpcBid"]) if obj.get("CpcBid") is not None else None,
                        "Network": obj.get("Network") if obj.get("Network") is not None else None,
                        "AdRotation": AdRotation.from_dict(obj["AdRotation"]) if obj.get("AdRotation") is not None else None,
                        "AudienceAdsBidAdjustment": obj.get("AudienceAdsBidAdjustment") if obj.get("AudienceAdsBidAdjustment") 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,
                        "BiddingScheme": BiddingScheme.from_dict(obj["BiddingScheme"]) if obj.get("BiddingScheme") is not None else None,
                        "Settings": [Setting.from_dict(_item) for _item in obj["Settings"]] if obj.get("Settings") is not None else None,
                        "AdScheduleUseSearcherTimeZone": obj.get("AdScheduleUseSearcherTimeZone") if obj.get("AdScheduleUseSearcherTimeZone") is not None else None,
                        "AdGroupType": obj.get("AdGroupType") if obj.get("AdGroupType") is not None else None,
                        "CpvBid": Bid.from_dict(obj["CpvBid"]) if obj.get("CpvBid") is not None else None,
                        "CpmBid": Bid.from_dict(obj["CpmBid"]) if obj.get("CpmBid") is not None else None,
                        "McpaBid": Bid.from_dict(obj["McpaBid"]) if obj.get("McpaBid") is not None else None,
                        "MultimediaAdsBidAdjustment": obj.get("MultimediaAdsBidAdjustment") if obj.get("MultimediaAdsBidAdjustment") is not None else None,
                        "CommissionRate": RateBid.from_dict(obj["CommissionRate"]) if obj.get("CommissionRate") is not None else None,
                        "PercentCpcBid": RateBid.from_dict(obj["PercentCpcBid"]) if obj.get("PercentCpcBid") is not None else None,
                        "UseOptimizedTargeting": obj.get("UseOptimizedTargeting") if obj.get("UseOptimizedTargeting") is not None else None,
                        "UsePredictiveTargeting": obj.get("UsePredictiveTargeting") if obj.get("UsePredictiveTargeting") is not None else None,
                        "FrequencyCapSettings": [FrequencyCapSettings.from_dict(_item) for _item in obj["FrequencyCapSettings"]] if obj.get("FrequencyCapSettings") 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
