# 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, StrictBool, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from typing import Optional, Set
from typing_extensions import Self

class Transaction(BaseModel):
    """
    Transaction
    """ # noqa: E501
    id: Optional[Annotated[int, Field(le=2147483647, strict=True, ge=1)]] = Field(default=None, description="ID of the Bank Account")
    description: Optional[StrictStr] = None
    var_date: Optional[date] = Field(default=None, alias="date")
    paid: Optional[StrictBool] = None
    amount_cents: Optional[Annotated[int, Field(le=2147483647, strict=True, ge=-2147483647)]] = None
    total_installments: Optional[Annotated[int, Field(le=2147483647, strict=True, ge=1)]] = None
    installment: Optional[Annotated[int, Field(le=2147483647, strict=True, ge=1)]] = None
    recurring: Optional[StrictBool] = None
    account_id: Optional[Annotated[int, Field(le=2147483647, strict=True, ge=1)]] = Field(default=None, description="ID of the Bank Account")
    account_type: Optional[StrictStr] = None
    category_id: Optional[Annotated[int, Field(le=2147483647, strict=True, ge=1)]] = None
    notes: Optional[StrictStr] = None
    attachments_count: Optional[Annotated[int, Field(le=2147483647, strict=True, ge=0)]] = None
    credit_card_id: Optional[Annotated[int, Field(le=2147483647, strict=True, ge=1)]] = None
    credit_card_invoice_id: Optional[Annotated[int, Field(le=2147483647, strict=True, ge=1)]] = None
    paid_credit_card_id: Optional[Annotated[int, Field(le=2147483647, strict=True, ge=1)]] = None
    paid_credit_card_invoice_id: Optional[Annotated[int, Field(le=2147483647, strict=True, ge=1)]] = None
    oposite_transaction_id: Optional[Annotated[int, Field(le=2147483647, strict=True, ge=1)]] = None
    oposite_account_id: Optional[Annotated[int, Field(le=2147483647, strict=True, ge=1)]] = Field(default=None, description="ID of the Bank Account")
    created_at: Optional[Annotated[str, Field(min_length=20, strict=True, max_length=29)]] = None
    updated_at: Optional[Annotated[str, Field(min_length=20, strict=True, max_length=29)]] = None
    tags: Optional[Annotated[List[StrictStr], Field(min_length=0, max_length=100)]] = None
    attachments: Optional[Annotated[List[StrictStr], Field(min_length=0, max_length=100)]] = None
    __properties: ClassVar[List[str]] = ["id", "description", "date", "paid", "amount_cents", "total_installments", "installment", "recurring", "account_id", "account_type", "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"]

    @field_validator('var_date')
    def var_date_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$", value):
            raise ValueError(r"must validate the regular expression /^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$/")
        return value

    @field_validator('account_type')
    def account_type_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['Account', 'CreditCard']):
            raise ValueError("must be one of enum values ('Account', 'CreditCard')")
        return value

    @field_validator('created_at')
    def created_at_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$", value):
            raise ValueError(r"must validate the regular expression /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/")
        return value

    @field_validator('updated_at')
    def updated_at_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$", value):
            raise ValueError(r"must validate the regular expression /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\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 Transaction 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 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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of Transaction 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"),
            "account_type": obj.get("account_type"),
            "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")
        })
        return _obj


