# 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.3.5
    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 WalletResponse(BaseModel):
    """
    WalletResponse
    """ # noqa: E501
    id: UUID
    customer_id: UUID
    name: Optional[StrictStr] = None
    code: Optional[StrictStr] = None
    status: StrictStr
    balance_cents: Annotated[str, Field(strict=True)]
    credits_balance: Annotated[str, Field(strict=True)]
    consumed_amount_cents: Annotated[str, Field(strict=True)]
    consumed_credits: Annotated[str, Field(strict=True)]
    rate_amount: Annotated[str, Field(strict=True)]
    currency: StrictStr
    expiration_at: Optional[datetime] = None
    priority: StrictInt
    created_at: datetime
    updated_at: datetime
    __properties: ClassVar[List[str]] = ["id", "customer_id", "name", "code", "status", "balance_cents", "credits_balance", "consumed_amount_cents", "consumed_credits", "rate_amount", "currency", "expiration_at", "priority", "created_at", "updated_at"]

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

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

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

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

    @field_validator('rate_amount')
    def rate_amount_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        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 WalletResponse 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 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 code (nullable) is None
        # and model_fields_set contains the field
        if self.code is None and "code" in self.model_fields_set:
            _dict['code'] = None

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of WalletResponse 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"),
            "customer_id": obj.get("customer_id"),
            "name": obj.get("name"),
            "code": obj.get("code"),
            "status": obj.get("status"),
            "balance_cents": obj.get("balance_cents"),
            "credits_balance": obj.get("credits_balance"),
            "consumed_amount_cents": obj.get("consumed_amount_cents"),
            "consumed_credits": obj.get("consumed_credits"),
            "rate_amount": obj.get("rate_amount"),
            "currency": obj.get("currency"),
            "expiration_at": obj.get("expiration_at"),
            "priority": obj.get("priority"),
            "created_at": obj.get("created_at"),
            "updated_at": obj.get("updated_at")
        })
        return _obj


