# coding: utf-8

"""
    Organizze API

    Specification for the Organizze API described in [https://github.com/organizze/api-doc](https://github.com/organizze/api-doc)

    The version of the OpenAPI document: 1.0.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 date
from pydantic import BaseModel, ConfigDict, Field, StrictInt
from typing import Any, ClassVar, Dict, List
from typing_extensions import Annotated
from organizze_api.models.transaction import Transaction
from typing import Optional, Set
from typing_extensions import Self

class CreditCardInvoiceFull(BaseModel):
    """
    CreditCardInvoiceFull
    """ # noqa: E501
    id: Annotated[int, Field(le=2147483647, strict=True, ge=1)]
    var_date: date = Field(alias="date")
    starting_date: date
    closing_date: date
    amount_cents: StrictInt
    payment_amount_cents: StrictInt
    balance_cents: StrictInt
    previous_balance_cents: StrictInt
    credit_card_id: Annotated[int, Field(le=2147483647, strict=True, ge=1)]
    transactions: Annotated[List[Transaction], Field(min_length=0)]
    payments: Annotated[List[Transaction], Field(min_length=0)]
    __properties: ClassVar[List[str]] = ["id", "date", "starting_date", "closing_date", "amount_cents", "payment_amount_cents", "balance_cents", "previous_balance_cents", "credit_card_id", "transactions", "payments"]

    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 CreditCardInvoiceFull 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 transactions (list)
        _items = []
        if self.transactions:
            for _item_transactions in self.transactions:
                if _item_transactions:
                    _items.append(_item_transactions.to_dict())
            _dict['transactions'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in payments (list)
        _items = []
        if self.payments:
            for _item_payments in self.payments:
                if _item_payments:
                    _items.append(_item_payments.to_dict())
            _dict['payments'] = _items
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of CreditCardInvoiceFull 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"),
            "date": obj.get("date"),
            "starting_date": obj.get("starting_date"),
            "closing_date": obj.get("closing_date"),
            "amount_cents": obj.get("amount_cents"),
            "payment_amount_cents": obj.get("payment_amount_cents"),
            "balance_cents": obj.get("balance_cents"),
            "previous_balance_cents": obj.get("previous_balance_cents"),
            "credit_card_id": obj.get("credit_card_id"),
            "transactions": [Transaction.from_dict(_item) for _item in obj["transactions"]] if obj.get("transactions") is not None else None,
            "payments": [Transaction.from_dict(_item) for _item in obj["payments"]] if obj.get("payments") is not None else None
        })
        return _obj


