# 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.broad_match_search_query_kpi import BroadMatchSearchQueryKPI
from typing_extensions import Self

class BroadMatchKeywordOpportunity(BaseModel):
    """
    BroadMatchKeywordOpportunity
    """ # noqa: E501
    click_share: Optional[StrictFloat] = Field(default=None, alias="ClickShare")
    average_ctr: Optional[StrictFloat] = Field(default=None, alias="AverageCTR")
    average_cpc: Optional[StrictFloat] = Field(default=None, alias="AverageCPC")
    reference_keyword_id: Optional[StrictStr] = Field(default=None, alias="ReferenceKeywordId")
    reference_keyword_bid: Optional[StrictFloat] = Field(default=None, alias="ReferenceKeywordBid")
    reference_keyword_match_type: Optional[StrictInt] = Field(default=None, alias="ReferenceKeywordMatchType")
    impression_share: Optional[StrictFloat] = Field(default=None, alias="ImpressionShare")
    search_query_kpis: Optional[List[Optional[BroadMatchSearchQueryKPI]]] = Field(default=None, alias="SearchQueryKPIs")
    ad_group_id: Optional[StrictStr] = Field(default=None, alias="AdGroupId")
    campaign_id: Optional[StrictStr] = Field(default=None, alias="CampaignId")
    ad_group_name: Optional[StrictStr] = Field(default=None, alias="AdGroupName")
    campaign_name: Optional[StrictStr] = Field(default=None, alias="CampaignName")
    match_type: Optional[StrictInt] = Field(default=None, alias="MatchType")
    suggested_keyword: Optional[StrictStr] = Field(default=None, alias="SuggestedKeyword")
    suggested_bid: Optional[StrictFloat] = Field(default=None, alias="SuggestedBid")
    monthly_searches: Optional[StrictStr] = Field(default=None, alias="MonthlySearches")
    competition: Optional[StrictFloat] = Field(default=None, alias="Competition")
    estimated_increase_in_clicks: Optional[StrictFloat] = Field(default=None, alias="EstimatedIncreaseInClicks")
    estimated_increase_in_cost: Optional[StrictFloat] = Field(default=None, alias="EstimatedIncreaseInCost")
    estimated_increase_in_impressions: Optional[StrictStr] = Field(default=None, alias="EstimatedIncreaseInImpressions")
    opportunity_key: Optional[StrictStr] = Field(default=None, alias="OpportunityKey")
    type: Optional[StrictStr] = Field(default='BroadMatchKeywordOpportunity', alias="Type")
    __properties: ClassVar[List[str]] = ["ClickShare", "AverageCTR", "AverageCPC", "ReferenceKeywordId", "ReferenceKeywordBid", "ReferenceKeywordMatchType", "ImpressionShare", "SearchQueryKPIs", "AdGroupId", "CampaignId", "AdGroupName", "CampaignName", "MatchType", "SuggestedKeyword", "SuggestedBid", "MonthlySearches", "Competition", "EstimatedIncreaseInClicks", "EstimatedIncreaseInCost", "EstimatedIncreaseInImpressions", "OpportunityKey", "Type"]

    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 BroadMatchKeywordOpportunity 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 each item in search_query_kpis (list)
        _items = []
        if self.search_query_kpis:
            for _item_search_query_kpis in self.search_query_kpis:
                if _item_search_query_kpis:
                    _items.append(_item_search_query_kpis.to_dict())
            _dict['SearchQueryKpis'] = _items
        # set to None if click_share (nullable) is None
        # and model_fields_set contains the field
        if self.click_share is None and "click_share" in self.model_fields_set:
            _dict['ClickShare'] = None

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

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

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

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

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

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

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

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

        # 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 ad_group_name (nullable) is None
        # and model_fields_set contains the field
        if self.ad_group_name is None and "ad_group_name" in self.model_fields_set:
            _dict['AdGroupName'] = None

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "ClickShare": obj.get("ClickShare") if obj.get("ClickShare") is not None else None,
                        "AverageCTR": obj.get("AverageCTR") if obj.get("AverageCTR") is not None else None,
                        "AverageCPC": obj.get("AverageCPC") if obj.get("AverageCPC") is not None else None,
                        "ReferenceKeywordId": obj.get("ReferenceKeywordId") if obj.get("ReferenceKeywordId") is not None else None,
                        "ReferenceKeywordBid": obj.get("ReferenceKeywordBid") if obj.get("ReferenceKeywordBid") is not None else None,
                        "ReferenceKeywordMatchType": obj.get("ReferenceKeywordMatchType") if obj.get("ReferenceKeywordMatchType") is not None else None,
                        "ImpressionShare": obj.get("ImpressionShare") if obj.get("ImpressionShare") is not None else None,
                        "SearchQueryKPIs": [BroadMatchSearchQueryKPI.from_dict(_item) for _item in obj["SearchQueryKpis"]] if obj.get("SearchQueryKpis") is not None else None,
                        "AdGroupId": obj.get("AdGroupId") if obj.get("AdGroupId") is not None else None,
                        "CampaignId": obj.get("CampaignId") if obj.get("CampaignId") is not None else None,
                        "AdGroupName": obj.get("AdGroupName") if obj.get("AdGroupName") is not None else None,
                        "CampaignName": obj.get("CampaignName") if obj.get("CampaignName") is not None else None,
                        "MatchType": obj.get("MatchType") if obj.get("MatchType") is not None else None,
                        "SuggestedKeyword": obj.get("SuggestedKeyword") if obj.get("SuggestedKeyword") is not None else None,
                        "SuggestedBid": obj.get("SuggestedBid") if obj.get("SuggestedBid") is not None else None,
                        "MonthlySearches": obj.get("MonthlySearches") if obj.get("MonthlySearches") is not None else None,
                        "Competition": obj.get("Competition") if obj.get("Competition") is not None else None,
                        "EstimatedIncreaseInClicks": obj.get("EstimatedIncreaseInClicks") if obj.get("EstimatedIncreaseInClicks") is not None else None,
                        "EstimatedIncreaseInCost": obj.get("EstimatedIncreaseInCost") if obj.get("EstimatedIncreaseInCost") is not None else None,
                        "EstimatedIncreaseInImpressions": obj.get("EstimatedIncreaseInImpressions") if obj.get("EstimatedIncreaseInImpressions") is not None else None,
                        "OpportunityKey": obj.get("OpportunityKey") if obj.get("OpportunityKey") is not None else None,
                        "Type": obj.get("Type") if obj.get("Type") is not None else 'BroadMatchKeywordOpportunity'
        })
        return _obj
