# coding: utf-8

"""
    Accounting service API

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: v0
    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, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from cloudbeds_accounting.models.balance_breakdown_item import BalanceBreakdownItem
from typing import Optional, Set
from typing_extensions import Self

class SourceBalanceResponse(BaseModel):
    """
    SourceBalanceResponse
    """ # noqa: E501
    currency: Optional[StrictStr] = Field(default=None, description="Currency code (e.g., USD)")
    currency_scale: Optional[StrictInt] = Field(default=None, description="Number of decimal places for the currency", alias="currencyScale")
    grand_total: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Grand total amount in smallest currency unit", alias="grandTotal")
    subtotal: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Subtotal amount in smallest currency unit")
    additional_items: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Additional items amount in smallest currency unit", alias="additionalItems")
    ar_transfer: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Accounts receivable transfer amount in smallest currency unit", alias="arTransfer")
    amount_paid: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Amount paid in smallest currency unit", alias="amountPaid")
    refund_issued: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Refund issued amount in smallest currency unit", alias="refundIssued")
    upcoming_payments: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Upcoming payments amount in smallest currency unit", alias="upcomingPayments")
    upcoming_refund: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Upcoming refund amount in smallest currency unit", alias="upcomingRefund")
    cancellation_fee: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Cancellation fee amount in smallest currency unit", alias="cancellationFee")
    no_show_fee: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="No show fee amount in smallest currency unit", alias="noShowFee")
    tax_breakdown: Optional[List[BalanceBreakdownItem]] = Field(default=None, description="Tax breakdown details as array of items with id and amount", alias="taxBreakdown")
    fee_breakdown: Optional[List[BalanceBreakdownItem]] = Field(default=None, description="Fee breakdown details as array of items with id and amount", alias="feeBreakdown")
    balance_due: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Balance due amount in smallest currency unit", alias="balanceDue")
    updated_at: Optional[datetime] = Field(default=None, description="Timestamp when the balance was last updated (UTC)", alias="updatedAt")
    __properties: ClassVar[List[str]] = ["currency", "currencyScale", "grandTotal", "subtotal", "additionalItems", "arTransfer", "amountPaid", "refundIssued", "upcomingPayments", "upcomingRefund", "cancellationFee", "noShowFee", "taxBreakdown", "feeBreakdown", "balanceDue", "updatedAt"]

    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 SourceBalanceResponse 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 tax_breakdown (list)
        _items = []
        if self.tax_breakdown:
            for _item_tax_breakdown in self.tax_breakdown:
                if _item_tax_breakdown:
                    _items.append(_item_tax_breakdown.to_dict())
            _dict['taxBreakdown'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in fee_breakdown (list)
        _items = []
        if self.fee_breakdown:
            for _item_fee_breakdown in self.fee_breakdown:
                if _item_fee_breakdown:
                    _items.append(_item_fee_breakdown.to_dict())
            _dict['feeBreakdown'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "currency": obj.get("currency"),
            "currencyScale": obj.get("currencyScale"),
            "grandTotal": obj.get("grandTotal"),
            "subtotal": obj.get("subtotal"),
            "additionalItems": obj.get("additionalItems"),
            "arTransfer": obj.get("arTransfer"),
            "amountPaid": obj.get("amountPaid"),
            "refundIssued": obj.get("refundIssued"),
            "upcomingPayments": obj.get("upcomingPayments"),
            "upcomingRefund": obj.get("upcomingRefund"),
            "cancellationFee": obj.get("cancellationFee"),
            "noShowFee": obj.get("noShowFee"),
            "taxBreakdown": [BalanceBreakdownItem.from_dict(_item) for _item in obj["taxBreakdown"]] if obj.get("taxBreakdown") is not None else None,
            "feeBreakdown": [BalanceBreakdownItem.from_dict(_item) for _item in obj["feeBreakdown"]] if obj.get("feeBreakdown") is not None else None,
            "balanceDue": obj.get("balanceDue"),
            "updatedAt": obj.get("updatedAt")
        })
        return _obj


