# coding: utf-8

"""
    AdInsightService

    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.adinsight.ad_group_estimator import AdGroupEstimator
from openapi_client.models.adinsight.criterion import Criterion
from openapi_client.models.adinsight.negative_keyword import NegativeKeyword
from typing_extensions import Self

class CampaignEstimator(BaseModel):
    """
    CampaignEstimator
    """ # noqa: E501
    campaign_id: Optional[StrictStr] = Field(default=None, alias="CampaignId")
    daily_budget: Optional[StrictFloat] = Field(default=None, alias="DailyBudget")
    criteria: Optional[List[Optional[Criterion]]] = Field(default=None, alias="Criteria")
    ad_group_estimators: Optional[List[Optional[AdGroupEstimator]]] = Field(default=None, alias="AdGroupEstimators")
    negative_keywords: Optional[List[Optional[NegativeKeyword]]] = Field(default=None, alias="NegativeKeywords")
    __properties: ClassVar[List[str]] = ["CampaignId", "DailyBudget", "Criteria", "AdGroupEstimators", "NegativeKeywords"]

    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 each item in criteria (list)
        _items = []
        if self.criteria:
            for _item_criteria in self.criteria:
                if _item_criteria:
                    _items.append(_item_criteria.to_dict())
            _dict['Criteria'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in ad_group_estimators (list)
        _items = []
        if self.ad_group_estimators:
            for _item_ad_group_estimators in self.ad_group_estimators:
                if _item_ad_group_estimators:
                    _items.append(_item_ad_group_estimators.to_dict())
            _dict['AdGroupEstimators'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in negative_keywords (list)
        _items = []
        if self.negative_keywords:
            for _item_negative_keywords in self.negative_keywords:
                if _item_negative_keywords:
                    _items.append(_item_negative_keywords.to_dict())
            _dict['NegativeKeywords'] = _items
        # set to None if campaign_id (nullable) is None
        # and model_fields_set contains the field
        if self.campaign_id is None and "campaign_id" in self.model_fields_set:
            _dict['CampaignId'] = None

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "CampaignId": obj.get("CampaignId") if obj.get("CampaignId") is not None else None,
                        "DailyBudget": obj.get("DailyBudget") if obj.get("DailyBudget") is not None else None,
                        "Criteria": [Criterion.from_dict(_item) for _item in obj["Criteria"]] if obj.get("Criteria") is not None else None,
                        "AdGroupEstimators": [AdGroupEstimator.from_dict(_item) for _item in obj["AdGroupEstimators"]] if obj.get("AdGroupEstimators") is not None else None,
                        "NegativeKeywords": [NegativeKeyword.from_dict(_item) for _item in obj["NegativeKeywords"]] if obj.get("NegativeKeywords") is not None else None
        })
        return _obj
