# 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 date, datetime
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictFloat, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional, Union
from cloudbeds_accounting.models.action import Action
from cloudbeds_accounting.models.reservation_status import ReservationStatus
from cloudbeds_accounting.models.user_model import UserModel
from typing import Optional, Set
from typing_extensions import Self

class ExtendedTransactionResponse(BaseModel):
    """
    ExtendedTransactionResponse
    """ # noqa: E501
    id: Optional[StrictStr] = Field(default=None, description="Id of the transaction.")
    transaction_date: Optional[datetime] = Field(default=None, description="Date time of the transaction.", alias="transactionDate")
    reservation_name: Optional[StrictStr] = Field(default=None, description="reservation name.", alias="reservationName")
    checkin_date: Optional[date] = Field(default=None, description="Check in date.", alias="checkinDate")
    checkout_date: Optional[date] = Field(default=None, description="Check out date.", alias="checkoutDate")
    amount: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="amount of the transaction.")
    reservation_id: Optional[StrictStr] = Field(default=None, description="Id of reservation", alias="reservationId")
    reservation_identifier: Optional[StrictStr] = Field(default=None, description="Identifier of reservation", alias="reservationIdentifier")
    internal_transaction_code: Optional[StrictStr] = Field(default=None, description="Internal Transaction Code", alias="internalTransactionCode")
    description: Optional[StrictStr] = Field(default=None, description="Description")
    notes: Optional[StrictStr] = Field(default=None, description="Notes")
    folio_id: Optional[StrictStr] = Field(default=None, description="Folio ID", alias="folioId")
    state: Optional[StrictStr] = None
    currency: Optional[StrictStr] = Field(default=None, description="Currency ISO code")
    currency_scale: Optional[StrictInt] = Field(default=None, description="Number of decimal places for the currency.", alias="currencyScale")
    reservation_status: Optional[ReservationStatus] = Field(default=None, alias="reservationStatus")
    posted: Optional[StrictBool] = Field(default=None, description="Flag to mark if transaction is posted")
    user: Optional[UserModel] = None
    actions: Optional[List[Action]] = Field(default=None, description="Returns the list of actions available for the transaction")
    __properties: ClassVar[List[str]] = ["id", "transactionDate", "reservationName", "checkinDate", "checkoutDate", "amount", "reservationId", "reservationIdentifier", "internalTransactionCode", "description", "notes", "folioId", "state", "currency", "currencyScale", "reservationStatus", "posted", "user", "actions"]

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

        if value not in set(['VOIDED', 'TRANSFERRED', 'CANCELLED', 'REFUNDED', 'DELETED']):
            raise ValueError("must be one of enum values ('VOIDED', 'TRANSFERRED', 'CANCELLED', 'REFUNDED', 'DELETED')")
        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 ExtendedTransactionResponse 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 user
        if self.user:
            _dict['user'] = self.user.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in actions (list)
        _items = []
        if self.actions:
            for _item_actions in self.actions:
                if _item_actions:
                    _items.append(_item_actions.to_dict())
            _dict['actions'] = _items
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of ExtendedTransactionResponse 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"),
            "transactionDate": obj.get("transactionDate"),
            "reservationName": obj.get("reservationName"),
            "checkinDate": obj.get("checkinDate"),
            "checkoutDate": obj.get("checkoutDate"),
            "amount": obj.get("amount"),
            "reservationId": obj.get("reservationId"),
            "reservationIdentifier": obj.get("reservationIdentifier"),
            "internalTransactionCode": obj.get("internalTransactionCode"),
            "description": obj.get("description"),
            "notes": obj.get("notes"),
            "folioId": obj.get("folioId"),
            "state": obj.get("state"),
            "currency": obj.get("currency"),
            "currencyScale": obj.get("currencyScale"),
            "reservationStatus": obj.get("reservationStatus"),
            "posted": obj.get("posted"),
            "user": UserModel.from_dict(obj["user"]) if obj.get("user") is not None else None,
            "actions": [Action.from_dict(_item) for _item in obj["actions"]] if obj.get("actions") is not None else None
        })
        return _obj


