# coding: utf-8

"""
    bxb API

    A comprehensive usage-based billing platform API. Manage customers, plans, subscriptions, invoices, payments, wallets, coupons, credit notes, taxes, webhooks, and more.

    The version of the OpenAPI document: 0.5.0
    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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from uuid import UUID
from typing import Optional, Set
from typing_extensions import Self

class AppliedCouponResponse(BaseModel):
    """
    AppliedCouponResponse
    """ # noqa: E501
    id: UUID
    coupon_id: UUID
    customer_id: UUID
    amount_cents: Optional[Annotated[str, Field(strict=True)]] = None
    amount_currency: Optional[StrictStr] = None
    percentage_rate: Optional[Annotated[str, Field(strict=True)]] = None
    frequency: StrictStr
    frequency_duration: Optional[StrictInt] = None
    frequency_duration_remaining: Optional[StrictInt] = None
    status: StrictStr
    terminated_at: Optional[datetime] = None
    created_at: datetime
    updated_at: datetime
    __properties: ClassVar[List[str]] = ["id", "coupon_id", "customer_id", "amount_cents", "amount_currency", "percentage_rate", "frequency", "frequency_duration", "frequency_duration_remaining", "status", "terminated_at", "created_at", "updated_at"]

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

        if not re.match(r"^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$", value):
            raise ValueError(r"must validate the regular expression /^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$/")
        return value

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

        if not re.match(r"^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$", value):
            raise ValueError(r"must validate the regular expression /^(?!^[-+.]*$)[+-]?0*\d*\.?\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 AppliedCouponResponse 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 amount_cents (nullable) is None
        # and model_fields_set contains the field
        if self.amount_cents is None and "amount_cents" in self.model_fields_set:
            _dict['amount_cents'] = None

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "coupon_id": obj.get("coupon_id"),
            "customer_id": obj.get("customer_id"),
            "amount_cents": obj.get("amount_cents"),
            "amount_currency": obj.get("amount_currency"),
            "percentage_rate": obj.get("percentage_rate"),
            "frequency": obj.get("frequency"),
            "frequency_duration": obj.get("frequency_duration"),
            "frequency_duration_remaining": obj.get("frequency_duration_remaining"),
            "status": obj.get("status"),
            "terminated_at": obj.get("terminated_at"),
            "created_at": obj.get("created_at"),
            "updated_at": obj.get("updated_at")
        })
        return _obj


