# 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, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from pinterestsdk.models.entity_status import EntityStatus
from pinterestsdk.models.promotion_template_value import PromotionTemplateValue
from pinterestsdk.models.promotion_type import PromotionType
from typing import Optional, Set
from typing_extensions import Self

class PromotionUpdateRequest(BaseModel):
    """
    PromotionUpdateRequest
    """ # noqa: E501
    discount_status: Optional[StrictStr] = Field(default=None, description="Discount status based on the current time and start and end time of discount")
    end_time: Optional[StrictInt] = Field(default=None, description="Promotion end time. Unix timestamp in seconds. Independent of campaign end time.")
    external_id: Optional[Annotated[str, Field(strict=True, max_length=64)]] = Field(default=None, description="Platform-specific ID for this promotion. Will be null for promotions first created within Pinterest.")
    platform_type: Optional[StrictStr] = Field(default=None, description="The source integration platform used when creating the promotion. Currently supported values are 'DEFAULT' and 'SHOPIFY'.")
    promotion_code: Optional[StrictStr] = Field(default=None, description="Code that can be used to redeem a promotion.")
    promotion_custom_id: Optional[Annotated[str, Field(strict=True, max_length=50)]] = Field(default=None, description="An optional field for user defined promotion ID for this promotion. Will copy from Pinterest system generated ID if user did not provide one.")
    promotion_title: Optional[StrictStr] = Field(default=None, description="Internal name for the promotion.")
    promotion_type: Optional[PromotionType] = None
    start_time: Optional[StrictInt] = Field(default=None, description="Promotion start time. Unix timestamp in seconds. Independent of campaign start time.")
    template_values: Optional[Annotated[List[PromotionTemplateValue], Field(min_length=0, max_length=2)]] = Field(default=None, description="List of values to be inserted in the promotion type-specific template.")
    id: Annotated[str, Field(strict=True)] = Field(description="Promotion ID")
    status: Optional[EntityStatus] = None
    __properties: ClassVar[List[str]] = ["discount_status", "end_time", "external_id", "platform_type", "promotion_code", "promotion_custom_id", "promotion_title", "promotion_type", "start_time", "template_values", "id", "status"]

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

        if value not in set(['OTHER', 'ACTIVE', 'PAUSED', 'SCHEDULED', 'EXPIRED']):
            raise ValueError("must be one of enum values ('OTHER', 'ACTIVE', 'PAUSED', 'SCHEDULED', 'EXPIRED')")
        return value

    @field_validator('id')
    def 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

    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 PromotionUpdateRequest 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 template_values (list)
        _items = []
        if self.template_values:
            for _item_template_values in self.template_values:
                if _item_template_values:
                    _items.append(_item_template_values.to_dict())
            _dict['template_values'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "discount_status": obj.get("discount_status"),
            "end_time": obj.get("end_time"),
            "external_id": obj.get("external_id"),
            "platform_type": obj.get("platform_type"),
            "promotion_code": obj.get("promotion_code"),
            "promotion_custom_id": obj.get("promotion_custom_id"),
            "promotion_title": obj.get("promotion_title"),
            "promotion_type": obj.get("promotion_type"),
            "start_time": obj.get("start_time"),
            "template_values": [PromotionTemplateValue.from_dict(_item) for _item in obj["template_values"]] if obj.get("template_values") is not None else None,
            "id": obj.get("id"),
            "status": obj.get("status")
        })
        return _obj


