# 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.creative_type import CreativeType
from pinterestsdk.models.customizable_cta_type import CustomizableCTAType
from pinterestsdk.models.disclosure_type import DisclosureType
from pinterestsdk.models.entity_status import EntityStatus
from pinterestsdk.models.grid_click_type import GridClickType
from pinterestsdk.models.quiz_pin_data import QuizPinData
from pinterestsdk.models.tracking_urls import TrackingUrls
from typing import Optional, Set
from typing_extensions import Self

class AdCommon(BaseModel):
    """
    Creation fields
    """ # noqa: E501
    ad_group_id: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="ID of the ad group that contains the ad.")
    android_deep_link: Optional[StrictStr] = Field(default=None, description="Deep link URL for Android devices.")
    carousel_android_deep_links: Optional[List[StrictStr]] = Field(default=None, description="Comma-separated deep links for the carousel pin on Android.")
    carousel_destination_urls: Optional[List[StrictStr]] = Field(default=None, description="Comma-separated destination URLs for the carousel pin to promote.")
    carousel_ios_deep_links: Optional[List[StrictStr]] = Field(default=None, description="Comma-separated deep links for the carousel pin on iOS.")
    click_tracking_url: Optional[StrictStr] = Field(default=None, description="Tracking url for the ad clicks.")
    creative_type: Optional[CreativeType] = None
    customizable_cta_type: Optional[CustomizableCTAType] = None
    destination_url: Optional[StrictStr] = Field(default=None, description="Destination URL.")
    disclosure_type: Optional[DisclosureType] = None
    disclosure_url: Optional[StrictStr] = Field(default=None, description="URL for a page that provides disclosures about a pharmaceutical product, such as potential side effects. Make sure the URL takes the user directly to the disclosure content and the referenced site is secure.")
    grid_click_type: Optional[GridClickType] = None
    ios_deep_link: Optional[StrictStr] = Field(default=None, description="Deep link URL for iOS devices.")
    is_pin_deleted: Optional[StrictBool] = Field(default=None, description="Is original pin deleted?")
    is_removable: Optional[StrictBool] = Field(default=None, description="Is pin repinnable?")
    lead_form_id: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="Lead form ID for lead ad generation.")
    name: Optional[StrictStr] = Field(default=None, description="Name of the ad - 255 chars max.")
    quiz_pin_data: Optional[QuizPinData] = Field(default=None, description="Before creating a quiz ad, you must create an organic Pin using POST/Create Pin for each result in the quiz. Quiz ads cannot be saved by a Pinner. Quiz ad results can be saved.")
    status: Optional[EntityStatus] = None
    tracking_urls: Optional[TrackingUrls] = None
    view_tracking_url: Optional[StrictStr] = Field(default=None, description="Tracking URL for ad impressions.")
    __properties: ClassVar[List[str]] = ["ad_group_id", "android_deep_link", "carousel_android_deep_links", "carousel_destination_urls", "carousel_ios_deep_links", "click_tracking_url", "creative_type", "customizable_cta_type", "destination_url", "disclosure_type", "disclosure_url", "grid_click_type", "ios_deep_link", "is_pin_deleted", "is_removable", "lead_form_id", "name", "quiz_pin_data", "status", "tracking_urls", "view_tracking_url"]

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

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

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

        if not re.match(r"^(AG)?\d+$", value):
            raise ValueError(r"must validate the regular expression /^(AG)?\d+$/")
        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 AdCommon 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 quiz_pin_data
        if self.quiz_pin_data:
            _dict['quiz_pin_data'] = self.quiz_pin_data.to_dict()
        # override the default output from pydantic by calling `to_dict()` of tracking_urls
        if self.tracking_urls:
            _dict['tracking_urls'] = self.tracking_urls.to_dict()
        # set to None if android_deep_link (nullable) is None
        # and model_fields_set contains the field
        if self.android_deep_link is None and "android_deep_link" in self.model_fields_set:
            _dict['android_deep_link'] = None

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

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

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

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

        # 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

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "ad_group_id": obj.get("ad_group_id"),
            "android_deep_link": obj.get("android_deep_link"),
            "carousel_android_deep_links": obj.get("carousel_android_deep_links"),
            "carousel_destination_urls": obj.get("carousel_destination_urls"),
            "carousel_ios_deep_links": obj.get("carousel_ios_deep_links"),
            "click_tracking_url": obj.get("click_tracking_url"),
            "creative_type": obj.get("creative_type"),
            "customizable_cta_type": obj.get("customizable_cta_type"),
            "destination_url": obj.get("destination_url"),
            "disclosure_type": obj.get("disclosure_type"),
            "disclosure_url": obj.get("disclosure_url"),
            "grid_click_type": obj.get("grid_click_type"),
            "ios_deep_link": obj.get("ios_deep_link"),
            "is_pin_deleted": obj.get("is_pin_deleted"),
            "is_removable": obj.get("is_removable"),
            "lead_form_id": obj.get("lead_form_id"),
            "name": obj.get("name"),
            "quiz_pin_data": QuizPinData.from_dict(obj["quiz_pin_data"]) if obj.get("quiz_pin_data") is not None else None,
            "status": obj.get("status"),
            "tracking_urls": TrackingUrls.from_dict(obj["tracking_urls"]) if obj.get("tracking_urls") is not None else None,
            "view_tracking_url": obj.get("view_tracking_url")
        })
        return _obj


