# 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.search_counts_by_attributes import SearchCountsByAttributes
from typing_extensions import Self

class KeywordSearchCount(BaseModel):
    """
    KeywordSearchCount
    """ # noqa: E501
    keyword: Optional[StrictStr] = Field(default=None, alias="Keyword")
    search_counts_by_attributes: Optional[List[Optional[SearchCountsByAttributes]]] = Field(default=None, alias="SearchCountsByAttributes")
    __properties: ClassVar[List[str]] = ["Keyword", "SearchCountsByAttributes"]

    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 search_counts_by_attributes (list)
        _items = []
        if self.search_counts_by_attributes:
            for _item_search_counts_by_attributes in self.search_counts_by_attributes:
                if _item_search_counts_by_attributes:
                    _items.append(_item_search_counts_by_attributes.to_dict())
            _dict['SearchCountsByAttributes'] = _items
        # set to None if keyword (nullable) is None
        # and model_fields_set contains the field
        if self.keyword is None and "keyword" in self.model_fields_set:
            _dict['Keyword'] = None

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

        return _dict

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

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

        _obj = cls.model_validate({
            "Keyword": obj.get("Keyword") if obj.get("Keyword") is not None else None,
                        "SearchCountsByAttributes": [SearchCountsByAttributes.from_dict(_item) for _item in obj["SearchCountsByAttributes"]] if obj.get("SearchCountsByAttributes") is not None else None
        })
        return _obj
