# coding: utf-8

"""
    (v2.0) Dynamics 365 Business Central

    (v2.0) Business Central Standard APIs

    The version of the OpenAPI document: 2.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 datetime
from pydantic import BaseModel, ConfigDict, Field, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from pybusinesscentral.model.account import Account
from typing import Optional, Set
from typing_extensions import Self

class TrialBalance(BaseModel):
    """
    TrialBalance
    """ # noqa: E501
    number: Optional[Annotated[str, Field(strict=True, max_length=20)]] = Field(default=None, description="(v1.0) The number property for the Dynamics 365 Business Central trialBalance entity")
    account_id: Optional[StrictStr] = Field(default=None, description="(v1.0) The accountId property for the Dynamics 365 Business Central trialBalance entity", alias="accountId")
    account_type: Optional[StrictStr] = Field(default=None, description="(v1.0) The accountType property for the Dynamics 365 Business Central trialBalance entity", alias="accountType")
    display: Optional[Annotated[str, Field(strict=True, max_length=100)]] = Field(default=None, description="(v1.0) The display property for the Dynamics 365 Business Central trialBalance entity")
    total_debit: Optional[Annotated[str, Field(strict=True, max_length=30)]] = Field(default=None, description="(v1.0) The totalDebit property for the Dynamics 365 Business Central trialBalance entity", alias="totalDebit")
    total_credit: Optional[Annotated[str, Field(strict=True, max_length=30)]] = Field(default=None, description="(v1.0) The totalCredit property for the Dynamics 365 Business Central trialBalance entity", alias="totalCredit")
    balance_at_date_debit: Optional[Annotated[str, Field(strict=True, max_length=30)]] = Field(default=None, description="(v1.0) The balanceAtDateDebit property for the Dynamics 365 Business Central trialBalance entity", alias="balanceAtDateDebit")
    balance_at_date_credit: Optional[Annotated[str, Field(strict=True, max_length=30)]] = Field(default=None, description="(v1.0) The balanceAtDateCredit property for the Dynamics 365 Business Central trialBalance entity", alias="balanceAtDateCredit")
    date_filter: Optional[datetime] = Field(default=None, description="(v1.0) The dateFilter property for the Dynamics 365 Business Central trialBalance entity", alias="dateFilter")
    account: Optional[Account] = None
    __properties: ClassVar[List[str]] = ["number", "accountId", "accountType", "display", "totalDebit", "totalCredit", "balanceAtDateDebit", "balanceAtDateCredit", "dateFilter", "account"]

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

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

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

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

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of TrialBalance from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "number": obj.get("number"),
            "accountId": obj.get("accountId"),
            "accountType": obj.get("accountType"),
            "display": obj.get("display"),
            "totalDebit": obj.get("totalDebit"),
            "totalCredit": obj.get("totalCredit"),
            "balanceAtDateDebit": obj.get("balanceAtDateDebit"),
            "balanceAtDateCredit": obj.get("balanceAtDateCredit"),
            "dateFilter": obj.get("dateFilter"),
            "account": Account.from_dict(obj["account"]) if obj.get("account") is not None else None
        })
        return _obj


