# 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, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from pinterestsdk.models.customizable_cta_type import CustomizableCTAType
from typing import Optional, Set
from typing_extensions import Self

class AdPreviewShopping(BaseModel):
    """
    AdPreviewShopping
    """ # noqa: E501
    catalog_product_group_id: Annotated[str, Field(strict=True)] = Field(description="Catalog Product Group Id.")
    creative_type: StrictStr = Field(description="Ad format of the shopping ad preview.")
    customizable_cta_type: Optional[CustomizableCTAType] = Field(default=None, description="Select a call to action (CTA) to display below your ad. CTA options for catalog sales campaigns are `SHOP_NOW`, `BOOK_NOW`, `ON_SALE`, `GET_DEAL`, `BUY_ONLINE_PICKUP_IN_STORE`")
    hero_image_title: Optional[StrictStr] = Field(default=None, description="Title displayed below ad.")
    hero_image_url: Optional[StrictStr] = Field(default=None, description="Hero image URL.")
    hero_pin_id: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="Pin id for the hero image. When creative type is COLLECTION, either hero_pin_id or (hero_image_url, hero_image_title) is required.")
    image_tag: Optional[StrictStr] = Field(default=None, description="Multi image template tag.")
    item_id: Optional[StrictStr] = Field(default=None, description="Item id for product to preview standard shopping ads, optional and only applicable when creative type is SHOPPING.")
    preferred_media_type: Optional[StrictStr] = Field(default=None, description="Preferred media type.")
    video_tag: Optional[StrictStr] = Field(default=None, description="Multi video template tag, image_tag and video_tag are mutual exclusive.")
    __properties: ClassVar[List[str]] = ["catalog_product_group_id", "creative_type", "customizable_cta_type", "hero_image_title", "hero_image_url", "hero_pin_id", "image_tag", "item_id", "preferred_media_type", "video_tag"]

    @field_validator('catalog_product_group_id')
    def catalog_product_group_id_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"^\d+$", value):
            raise ValueError(r"must validate the regular expression /^\d+$/")
        return value

    @field_validator('creative_type')
    def creative_type_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['SHOPPING', 'CAROUSEL', 'COLLECTION', 'REGULAR']):
            raise ValueError("must be one of enum values ('SHOPPING', 'CAROUSEL', 'COLLECTION', 'REGULAR')")
        return value

    @field_validator('hero_pin_id')
    def hero_pin_id_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^\d+$", value):
            raise ValueError(r"must validate the regular expression /^\d+$/")
        return value

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

        if value not in set(['VIDEO', 'IMAGE']):
            raise ValueError("must be one of enum values ('VIDEO', 'IMAGE')")
        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 AdPreviewShopping 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,
        )
        # set to None if customizable_cta_type (nullable) is None
        # and model_fields_set contains the field
        if self.customizable_cta_type is None and "customizable_cta_type" in self.model_fields_set:
            _dict['customizable_cta_type'] = None

        return _dict

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

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

        _obj = cls.model_validate({
            "catalog_product_group_id": obj.get("catalog_product_group_id"),
            "creative_type": obj.get("creative_type"),
            "customizable_cta_type": obj.get("customizable_cta_type"),
            "hero_image_title": obj.get("hero_image_title"),
            "hero_image_url": obj.get("hero_image_url"),
            "hero_pin_id": obj.get("hero_pin_id"),
            "image_tag": obj.get("image_tag"),
            "item_id": obj.get("item_id"),
            "preferred_media_type": obj.get("preferred_media_type"),
            "video_tag": obj.get("video_tag")
        })
        return _obj


