# coding: utf-8

"""
    Pinterest REST API

    Pinterest's REST API

    The version of the OpenAPI document: 5.23.0
    Contact: blah+oapicf@cliffano.com
    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 pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from pinterestsdk.models.predicted_time_series import PredictedTimeSeries
from pinterestsdk.models.time_series import TimeSeries
from pinterestsdk.models.trending_keyword_demographics import TrendingKeywordDemographics
from typing import Optional, Set
from typing_extensions import Self

class TrendingKeyword(BaseModel):
    """
    TrendingKeyword
    """ # noqa: E501
    demographics: Optional[TrendingKeywordDemographics] = None
    has_prediction: Optional[StrictBool] = Field(default=None, description="Indicates whether the keyword has a prediction available for the next 90 days.<br /> This field is only applicable when `include_prediction` query parameter is set to `true`. <br /> By default, the value is `false` and no prediction data is included in the response.")
    keyword: Optional[Annotated[str, Field(min_length=1, strict=True)]] = Field(default=None, description="The keyword that is trending.")
    pct_growth_mom: Optional[StrictInt] = Field(default=None, description="The month-over-month percent change in search volume for this keyword.<br /> For example, a value of \"400\" would represent a 400% increase in searches in the last 30 days compared to the month prior.<br /> **Note**: growth rates are rounded, with a maximum of +/- 10000% change.  A value of 10001 indicates that this keyword experienced > 10000% month-over-month growth.")
    pct_growth_wow: Optional[StrictInt] = Field(default=None, description="The week-over-week percent change in search volume for this keyword.<br /> For example, a value of \"50\" would represent a 50% increase in searches in the last seven days compared to the week prior.<br /> **Note**: growth rates are rounded, with a maximum of +/- 10000% change.  A value of 10001 indicates that this keyword experienced > 10000% week-over-week growth.")
    pct_growth_yoy: Optional[StrictInt] = Field(default=None, description="The year-over-year percent change in search volume for this keyword.<br /> For example, a value of \"-5\" would represent a 5% decrease in searches in the last 365 days compared to the month prior.<br /> **Note**: growth rates are rounded, with a maximum of +/- 10000% change.  A value of 10001 indicates that this keyword experienced > 10000% year-over-year growth.")
    predicted_time_series: Optional[PredictedTimeSeries] = None
    time_series: Optional[TimeSeries] = None
    __properties: ClassVar[List[str]] = ["demographics", "has_prediction", "keyword", "pct_growth_mom", "pct_growth_wow", "pct_growth_yoy", "predicted_time_series", "time_series"]

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


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    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 TrendingKeyword 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 demographics
        if self.demographics:
            _dict['demographics'] = self.demographics.to_dict()
        # override the default output from pydantic by calling `to_dict()` of predicted_time_series
        if self.predicted_time_series:
            _dict['predicted_time_series'] = self.predicted_time_series.to_dict()
        # override the default output from pydantic by calling `to_dict()` of time_series
        if self.time_series:
            _dict['time_series'] = self.time_series.to_dict()
        # set to None if demographics (nullable) is None
        # and model_fields_set contains the field
        if self.demographics is None and "demographics" in self.model_fields_set:
            _dict['demographics'] = None

        return _dict

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

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

        _obj = cls.model_validate({
            "demographics": TrendingKeywordDemographics.from_dict(obj["demographics"]) if obj.get("demographics") is not None else None,
            "has_prediction": obj.get("has_prediction"),
            "keyword": obj.get("keyword"),
            "pct_growth_mom": obj.get("pct_growth_mom"),
            "pct_growth_wow": obj.get("pct_growth_wow"),
            "pct_growth_yoy": obj.get("pct_growth_yoy"),
            "predicted_time_series": PredictedTimeSeries.from_dict(obj["predicted_time_series"]) if obj.get("predicted_time_series") is not None else None,
            "time_series": TimeSeries.from_dict(obj["time_series"]) if obj.get("time_series") is not None else None
        })
        return _obj


