# 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, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from pinterestsdk.models.ad_group_audience_sizing_request_keywords_inner import AdGroupAudienceSizingRequestKeywordsInner
from pinterestsdk.models.placement_group_type import PlacementGroupType
from pinterestsdk.models.targeting_spec import TargetingSpec
from typing import Optional, Set
from typing_extensions import Self

class AdGroupAudienceSizingRequest(BaseModel):
    """
    AdGroupAudienceSizingRequest
    """ # noqa: E501
    auto_targeting_enabled: Optional[StrictBool] = Field(default=True, description="Enable auto-targeting for ad group. Default value is True. Also known as <a href=\"https://help.pinterest.com/en/business/article/performance-plus-targeting\" target=\"_blank\">\"Pinterest Performance+ targeting\"</a>.")
    creative_types: Optional[List[StrictStr]] = Field(default=None, description="Pin creative types filter. </p><strong>Note:</strong> SHOP_THE_PIN has been deprecated. Please use COLLECTION instead.")
    keywords: Optional[List[AdGroupAudienceSizingRequestKeywordsInner]] = Field(default=None, description="Array of keyword objects. If the keywords field is missing, all keywords will be targeted.")
    placement_group: Optional[PlacementGroupType] = Field(default='ALL', description="<a href=\"/docs/redoc/#section/Placement-group\">Placement group</a>.")
    product_group_ids: Optional[List[Annotated[str, Field(strict=True)]]] = Field(default=None, description="Targeted product group IDs. </p><strong>Note:</strong> This can only be combined with shopping/catalog sales campaigns. For more information, <a href=\"https://help.pinterest.com/en/business/article/shopping-ads#section-14571\" target=\"_blank\">click here</a>. SHOPPING_RETARGETING must be included in targeting_spec object or this field will be ignored.")
    targeting_spec: Optional[TargetingSpec] = None
    __properties: ClassVar[List[str]] = ["auto_targeting_enabled", "creative_types", "keywords", "placement_group", "product_group_ids", "targeting_spec"]

    @field_validator('creative_types')
    def creative_types_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        for i in value:
            if i not in set(['REGULAR', 'VIDEO', 'SHOPPING', 'CAROUSEL', 'MAX_VIDEO', 'SHOP_THE_PIN', 'COLLECTION', 'IDEA']):
                raise ValueError("each list item must be one of ('REGULAR', 'VIDEO', 'SHOPPING', 'CAROUSEL', 'MAX_VIDEO', 'SHOP_THE_PIN', 'COLLECTION', 'IDEA')")
        return value

    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 AdGroupAudienceSizingRequest 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 keywords (list)
        _items = []
        if self.keywords:
            for _item_keywords in self.keywords:
                if _item_keywords:
                    _items.append(_item_keywords.to_dict())
            _dict['keywords'] = _items
        # override the default output from pydantic by calling `to_dict()` of targeting_spec
        if self.targeting_spec:
            _dict['targeting_spec'] = self.targeting_spec.to_dict()
        # set to None if creative_types (nullable) is None
        # and model_fields_set contains the field
        if self.creative_types is None and "creative_types" in self.model_fields_set:
            _dict['creative_types'] = None

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "auto_targeting_enabled": obj.get("auto_targeting_enabled") if obj.get("auto_targeting_enabled") is not None else True,
            "creative_types": obj.get("creative_types"),
            "keywords": [AdGroupAudienceSizingRequestKeywordsInner.from_dict(_item) for _item in obj["keywords"]] if obj.get("keywords") is not None else None,
            "placement_group": obj.get("placement_group") if obj.get("placement_group") is not None else 'ALL',
            "product_group_ids": obj.get("product_group_ids"),
            "targeting_spec": TargetingSpec.from_dict(obj["targeting_spec"]) if obj.get("targeting_spec") is not None else None
        })
        return _obj


