# 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, datetime
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from organizze_api.models.recurring_transaction_all_of_recurrence_attributes import RecurringTransactionAllOfRecurrenceAttributes
from typing import Optional, Set
from typing_extensions import Self

class RecurringTransaction(BaseModel):
    """
    Recurring Transaction
    """ # noqa: E501
    id: Annotated[int, Field(le=9223372036854775807, strict=True, ge=1)] = Field(description="ID of the Transaction")
    description: StrictStr
    var_date: date = Field(alias="date")
    paid: StrictBool
    amount_cents: Annotated[int, Field(le=2147483647, strict=True, ge=-2147483647)]
    total_installments: Annotated[int, Field(le=2147483647, strict=True, ge=1)]
    installment: Annotated[int, Field(le=2147483647, strict=True, ge=1)]
    recurring: StrictBool
    account_id: Annotated[int, Field(le=2147483647, strict=True, ge=1)] = Field(description="ID of the Bank Account")
    category_id: Annotated[int, Field(le=2147483647, strict=True, ge=1)]
    notes: Optional[StrictStr]
    attachments_count: Annotated[int, Field(le=2147483647, strict=True, ge=0)]
    credit_card_id: Optional[Annotated[int, Field(le=2147483647, strict=True, ge=1)]]
    credit_card_invoice_id: Optional[Annotated[int, Field(le=2147483647, strict=True, ge=1)]]
    paid_credit_card_id: Optional[Annotated[int, Field(le=2147483647, strict=True, ge=1)]]
    paid_credit_card_invoice_id: Optional[Annotated[int, Field(le=2147483647, strict=True, ge=1)]]
    oposite_transaction_id: Optional[Annotated[int, Field(le=9223372036854775807, strict=True, ge=1)]]
    oposite_account_id: Optional[Annotated[int, Field(le=2147483647, strict=True, ge=1)]] = Field(description="ID of the Bank Account")
    created_at: datetime
    updated_at: datetime
    tags: Optional[Annotated[List[StrictStr], Field(min_length=0, max_length=100)]]
    attachments: Optional[Annotated[List[StrictStr], Field(min_length=0, max_length=100)]]
    recurrence_id: Optional[Annotated[int, Field(le=9223372036854775807, strict=True, ge=1)]]
    recurrence_attributes: RecurringTransactionAllOfRecurrenceAttributes
    __properties: ClassVar[List[str]] = ["id", "description", "date", "paid", "amount_cents", "total_installments", "installment", "recurring", "account_id", "category_id", "notes", "attachments_count", "credit_card_id", "credit_card_invoice_id", "paid_credit_card_id", "paid_credit_card_invoice_id", "oposite_transaction_id", "oposite_account_id", "created_at", "updated_at", "tags", "attachments", "recurrence_id", "recurrence_attributes"]

    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 RecurringTransaction 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 recurrence_attributes
        if self.recurrence_attributes:
            _dict['recurrence_attributes'] = self.recurrence_attributes.to_dict()
        # set to None if notes (nullable) is None
        # and model_fields_set contains the field
        if self.notes is None and "notes" in self.model_fields_set:
            _dict['notes'] = None

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

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

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

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

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of RecurringTransaction 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"),
            "description": obj.get("description"),
            "date": obj.get("date"),
            "paid": obj.get("paid"),
            "amount_cents": obj.get("amount_cents"),
            "total_installments": obj.get("total_installments"),
            "installment": obj.get("installment"),
            "recurring": obj.get("recurring"),
            "account_id": obj.get("account_id"),
            "category_id": obj.get("category_id"),
            "notes": obj.get("notes"),
            "attachments_count": obj.get("attachments_count"),
            "credit_card_id": obj.get("credit_card_id"),
            "credit_card_invoice_id": obj.get("credit_card_invoice_id"),
            "paid_credit_card_id": obj.get("paid_credit_card_id"),
            "paid_credit_card_invoice_id": obj.get("paid_credit_card_invoice_id"),
            "oposite_transaction_id": obj.get("oposite_transaction_id"),
            "oposite_account_id": obj.get("oposite_account_id"),
            "created_at": obj.get("created_at"),
            "updated_at": obj.get("updated_at"),
            "tags": obj.get("tags"),
            "attachments": obj.get("attachments"),
            "recurrence_id": obj.get("recurrence_id"),
            "recurrence_attributes": RecurringTransactionAllOfRecurrenceAttributes.from_dict(obj["recurrence_attributes"]) if obj.get("recurrence_attributes") is not None else None
        })
        return _obj


