# 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, 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 CreditNoteResponse(BaseModel):
    """
    CreditNoteResponse
    """ # noqa: E501
    id: UUID
    number: StrictStr
    invoice_id: UUID
    customer_id: UUID
    credit_note_type: StrictStr
    status: StrictStr
    credit_status: Optional[StrictStr] = None
    refund_status: Optional[StrictStr] = None
    reason: StrictStr
    description: Optional[StrictStr] = None
    credit_amount_cents: Annotated[str, Field(strict=True)]
    refund_amount_cents: Annotated[str, Field(strict=True)]
    balance_amount_cents: Annotated[str, Field(strict=True)]
    total_amount_cents: Annotated[str, Field(strict=True)]
    taxes_amount_cents: Annotated[str, Field(strict=True)]
    currency: StrictStr
    issued_at: Optional[datetime] = None
    voided_at: Optional[datetime] = None
    created_at: datetime
    updated_at: datetime
    __properties: ClassVar[List[str]] = ["id", "number", "invoice_id", "customer_id", "credit_note_type", "status", "credit_status", "refund_status", "reason", "description", "credit_amount_cents", "refund_amount_cents", "balance_amount_cents", "total_amount_cents", "taxes_amount_cents", "currency", "issued_at", "voided_at", "created_at", "updated_at"]

    @field_validator('credit_amount_cents')
    def credit_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('refund_amount_cents')
    def refund_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('balance_amount_cents')
    def balance_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('total_amount_cents')
    def total_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('taxes_amount_cents')
    def taxes_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

    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 CreditNoteResponse 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 credit_status (nullable) is None
        # and model_fields_set contains the field
        if self.credit_status is None and "credit_status" in self.model_fields_set:
            _dict['credit_status'] = None

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of CreditNoteResponse 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"),
            "number": obj.get("number"),
            "invoice_id": obj.get("invoice_id"),
            "customer_id": obj.get("customer_id"),
            "credit_note_type": obj.get("credit_note_type"),
            "status": obj.get("status"),
            "credit_status": obj.get("credit_status"),
            "refund_status": obj.get("refund_status"),
            "reason": obj.get("reason"),
            "description": obj.get("description"),
            "credit_amount_cents": obj.get("credit_amount_cents"),
            "refund_amount_cents": obj.get("refund_amount_cents"),
            "balance_amount_cents": obj.get("balance_amount_cents"),
            "total_amount_cents": obj.get("total_amount_cents"),
            "taxes_amount_cents": obj.get("taxes_amount_cents"),
            "currency": obj.get("currency"),
            "issued_at": obj.get("issued_at"),
            "voided_at": obj.get("voided_at"),
            "created_at": obj.get("created_at"),
            "updated_at": obj.get("updated_at")
        })
        return _obj


