# 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, StrictFloat, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing_extensions import Annotated
from typing import Optional, Set
from typing_extensions import Self

class AdsCreditDiscountsResponse(BaseModel):
    """
    AdsCreditDiscountsResponse
    """ # noqa: E501
    active: Optional[StrictBool] = Field(default=None, description="True if the offer code is currently active.")
    advertiser_id: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="Advertiser ID the offer was applied to.")
    discount_currency: Optional[StrictStr] = Field(default=None, description="Currency value for the discount.", alias="discountCurrency")
    discount_in_micro_currency: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="The discount applied in the offer’s currency value.", alias="discountInMicroCurrency")
    discount_type: Optional[StrictStr] = Field(default=None, description="The type of discount of this credit", alias="discountType")
    remaining_discount_in_micro_currency: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="The credits left to spend.", alias="remainingDiscountInMicroCurrency")
    title: Optional[StrictStr] = Field(default=None, description="Human readable title of the offer code.")
    __properties: ClassVar[List[str]] = ["active", "advertiser_id", "discountCurrency", "discountInMicroCurrency", "discountType", "remainingDiscountInMicroCurrency", "title"]

    @field_validator('advertiser_id')
    def advertiser_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('discount_type')
    def discount_type_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['COUPON', 'CREDIT', 'COUPON_APPLIED', 'CREDIT_APPLIED', 'MARKETING_OFFER_CREDIT', 'MARKETING_OFFER_CREDIT_APPLIED', 'GOODWILL_CREDIT', 'GOODWILL_CREDIT_APPLIED', 'INTERNAL_CREDIT', 'INTERNAL_CREDIT_APPLIED', 'PREPAID_CREDIT', 'PREPAID_CREDIT_APPLIED', 'SALES_INCENTIVE_CREDIT', 'SALES_INCENTIVE_CREDIT_APPLIED', 'CREDIT_EXPIRED', 'FUTURE_CREDIT', 'REFERRAL_CREDIT', 'INVOICE_SALES_INCENTIVE_CREDIT', 'INVOICE_SALES_INCENTIVE_CREDIT_APPLIED', 'PREPAID_CREDIT_REFUND']):
            raise ValueError("must be one of enum values ('COUPON', 'CREDIT', 'COUPON_APPLIED', 'CREDIT_APPLIED', 'MARKETING_OFFER_CREDIT', 'MARKETING_OFFER_CREDIT_APPLIED', 'GOODWILL_CREDIT', 'GOODWILL_CREDIT_APPLIED', 'INTERNAL_CREDIT', 'INTERNAL_CREDIT_APPLIED', 'PREPAID_CREDIT', 'PREPAID_CREDIT_APPLIED', 'SALES_INCENTIVE_CREDIT', 'SALES_INCENTIVE_CREDIT_APPLIED', 'CREDIT_EXPIRED', 'FUTURE_CREDIT', 'REFERRAL_CREDIT', 'INVOICE_SALES_INCENTIVE_CREDIT', 'INVOICE_SALES_INCENTIVE_CREDIT_APPLIED', 'PREPAID_CREDIT_REFUND')")
        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 AdsCreditDiscountsResponse 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 discount_currency (nullable) is None
        # and model_fields_set contains the field
        if self.discount_currency is None and "discount_currency" in self.model_fields_set:
            _dict['discountCurrency'] = None

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "active": obj.get("active"),
            "advertiser_id": obj.get("advertiser_id"),
            "discountCurrency": obj.get("discountCurrency"),
            "discountInMicroCurrency": obj.get("discountInMicroCurrency"),
            "discountType": obj.get("discountType"),
            "remainingDiscountInMicroCurrency": obj.get("remainingDiscountInMicroCurrency"),
            "title": obj.get("title")
        })
        return _obj


