# coding: utf-8

"""
    Fiscal document service API

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

    The version of the OpenAPI document: v1
    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
from typing import Any, ClassVar, Dict, List, Optional, Union
from cloudbeds_fiscal_document.models.action import Action
from cloudbeds_fiscal_document.models.creation_method import CreationMethod
from cloudbeds_fiscal_document.models.fiscal_document_kind import FiscalDocumentKind
from cloudbeds_fiscal_document.models.fiscal_document_status import FiscalDocumentStatus
from cloudbeds_fiscal_document.models.government_integration import GovernmentIntegration
from cloudbeds_fiscal_document.models.latest_linked_document import LatestLinkedDocument
from cloudbeds_fiscal_document.models.linked_document import LinkedDocument
from cloudbeds_fiscal_document.models.recipient_details import RecipientDetails
from cloudbeds_fiscal_document.models.source_kind import SourceKind
from typing import Optional, Set
from typing_extensions import Self

class FiscalDocumentDetailedResponse(BaseModel):
    """
    FiscalDocumentDetailedResponse
    """ # noqa: E501
    id: Optional[StrictStr] = None
    number: Optional[StrictStr] = None
    property_id: Optional[StrictStr] = Field(default=None, alias="propertyId")
    user_id: Optional[StrictStr] = Field(default=None, alias="userId")
    user_full_name: Optional[StrictStr] = Field(default=None, alias="userFullName")
    source_name: Optional[StrictStr] = Field(default=None, alias="sourceName")
    source_id: Optional[StrictStr] = Field(default=None, alias="sourceId")
    source_kind: Optional[SourceKind] = Field(default=None, alias="sourceKind")
    kind: Optional[FiscalDocumentKind] = None
    invoice_date: Optional[date] = Field(default=None, alias="invoiceDate")
    invoice_date_property_timezone: Optional[date] = Field(default=None, alias="invoiceDatePropertyTimezone")
    file_name: Optional[StrictStr] = Field(default=None, alias="fileName")
    amount: Optional[Union[StrictFloat, StrictInt]] = None
    balance: Optional[Union[StrictFloat, StrictInt]] = None
    due_date: Optional[date] = Field(default=None, alias="dueDate")
    due_date_property_timezone: Optional[date] = Field(default=None, alias="dueDatePropertyTimezone")
    recipients: Optional[List[RecipientDetails]] = None
    status: Optional[FiscalDocumentStatus] = None
    origin: Optional[StrictStr] = None
    external_id: Optional[StrictStr] = Field(default=None, alias="externalId")
    fail_reason: Optional[StrictStr] = Field(default=None, alias="failReason")
    method: Optional[CreationMethod] = None
    created_at: Optional[datetime] = Field(default=None, alias="createdAt")
    parent_id: Optional[StrictStr] = Field(default=None, alias="parentId")
    updated_at: Optional[datetime] = Field(default=None, alias="updatedAt")
    government_integration: Optional[GovernmentIntegration] = Field(default=None, alias="governmentIntegration")
    latest_linked_document: Optional[LatestLinkedDocument] = Field(default=None, alias="latestLinkedDocument")
    linked_documents: Optional[List[LinkedDocument]] = Field(default=None, description="List of documents linked to this fiscal document (both parent and child relationships)", alias="linkedDocuments")
    actions: Optional[List[Action]] = Field(default=None, description="Returns the list of actions available for the transaction")
    source_identifier: Optional[StrictStr] = Field(default=None, description="Reservation Identifier or a group code", alias="sourceIdentifier")
    simplified: Optional[StrictBool] = Field(default=None, description="Applies to invoices only.")
    __properties: ClassVar[List[str]] = ["id", "number", "propertyId", "userId", "userFullName", "sourceName", "sourceId", "sourceKind", "kind", "invoiceDate", "invoiceDatePropertyTimezone", "fileName", "amount", "balance", "dueDate", "dueDatePropertyTimezone", "recipients", "status", "origin", "externalId", "failReason", "method", "createdAt", "parentId", "updatedAt", "governmentIntegration", "latestLinkedDocument", "linkedDocuments", "actions", "sourceIdentifier", "simplified"]

    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 FiscalDocumentDetailedResponse 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 recipients (list)
        _items = []
        if self.recipients:
            for _item_recipients in self.recipients:
                if _item_recipients:
                    _items.append(_item_recipients.to_dict())
            _dict['recipients'] = _items
        # override the default output from pydantic by calling `to_dict()` of government_integration
        if self.government_integration:
            _dict['governmentIntegration'] = self.government_integration.to_dict()
        # override the default output from pydantic by calling `to_dict()` of latest_linked_document
        if self.latest_linked_document:
            _dict['latestLinkedDocument'] = self.latest_linked_document.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in linked_documents (list)
        _items = []
        if self.linked_documents:
            for _item_linked_documents in self.linked_documents:
                if _item_linked_documents:
                    _items.append(_item_linked_documents.to_dict())
            _dict['linkedDocuments'] = _items
        # 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 FiscalDocumentDetailedResponse 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"),
            "number": obj.get("number"),
            "propertyId": obj.get("propertyId"),
            "userId": obj.get("userId"),
            "userFullName": obj.get("userFullName"),
            "sourceName": obj.get("sourceName"),
            "sourceId": obj.get("sourceId"),
            "sourceKind": obj.get("sourceKind"),
            "kind": obj.get("kind"),
            "invoiceDate": obj.get("invoiceDate"),
            "invoiceDatePropertyTimezone": obj.get("invoiceDatePropertyTimezone"),
            "fileName": obj.get("fileName"),
            "amount": obj.get("amount"),
            "balance": obj.get("balance"),
            "dueDate": obj.get("dueDate"),
            "dueDatePropertyTimezone": obj.get("dueDatePropertyTimezone"),
            "recipients": [RecipientDetails.from_dict(_item) for _item in obj["recipients"]] if obj.get("recipients") is not None else None,
            "status": obj.get("status"),
            "origin": obj.get("origin"),
            "externalId": obj.get("externalId"),
            "failReason": obj.get("failReason"),
            "method": obj.get("method"),
            "createdAt": obj.get("createdAt"),
            "parentId": obj.get("parentId"),
            "updatedAt": obj.get("updatedAt"),
            "governmentIntegration": GovernmentIntegration.from_dict(obj["governmentIntegration"]) if obj.get("governmentIntegration") is not None else None,
            "latestLinkedDocument": LatestLinkedDocument.from_dict(obj["latestLinkedDocument"]) if obj.get("latestLinkedDocument") is not None else None,
            "linkedDocuments": [LinkedDocument.from_dict(_item) for _item in obj["linkedDocuments"]] if obj.get("linkedDocuments") is not None else None,
            "actions": [Action.from_dict(_item) for _item in obj["actions"]] if obj.get("actions") is not None else None,
            "sourceIdentifier": obj.get("sourceIdentifier"),
            "simplified": obj.get("simplified")
        })
        return _obj


