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

class AgedAccountsReceivable(BaseModel):
    """
    AgedAccountsReceivable
    """ # noqa: E501
    customer_id: Optional[StrictStr] = Field(default=None, description="(v1.0) The customerId property for the Dynamics 365 Business Central agedAccountsReceivable entity", alias="customerId")
    customer_number: Optional[Annotated[str, Field(strict=True, max_length=20)]] = Field(default=None, description="(v1.0) The customerNumber property for the Dynamics 365 Business Central agedAccountsReceivable entity", alias="customerNumber")
    name: Optional[Annotated[str, Field(strict=True, max_length=100)]] = Field(default=None, description="(v1.0) The name property for the Dynamics 365 Business Central agedAccountsReceivable entity")
    currency_code: Optional[Annotated[str, Field(strict=True, max_length=10)]] = Field(default=None, description="(v1.0) The currencyCode property for the Dynamics 365 Business Central agedAccountsReceivable entity", alias="currencyCode")
    balance_due: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="(v1.0) The balanceDue property for the Dynamics 365 Business Central agedAccountsReceivable entity", alias="balanceDue")
    current_amount: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="(v1.0) The currentAmount property for the Dynamics 365 Business Central agedAccountsReceivable entity", alias="currentAmount")
    period1_amount: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="(v1.0) The period1Amount property for the Dynamics 365 Business Central agedAccountsReceivable entity", alias="period1Amount")
    period2_amount: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="(v1.0) The period2Amount property for the Dynamics 365 Business Central agedAccountsReceivable entity", alias="period2Amount")
    period3_amount: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="(v1.0) The period3Amount property for the Dynamics 365 Business Central agedAccountsReceivable entity", alias="period3Amount")
    aged_as_of_date: Optional[datetime] = Field(default=None, description="(v1.0) The agedAsOfDate property for the Dynamics 365 Business Central agedAccountsReceivable entity", alias="agedAsOfDate")
    period_length_filter: Optional[Annotated[str, Field(strict=True, max_length=10)]] = Field(default=None, description="(v1.0) The periodLengthFilter property for the Dynamics 365 Business Central agedAccountsReceivable entity", alias="periodLengthFilter")
    __properties: ClassVar[List[str]] = ["customerId", "customerNumber", "name", "currencyCode", "balanceDue", "currentAmount", "period1Amount", "period2Amount", "period3Amount", "agedAsOfDate", "periodLengthFilter"]

    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 AgedAccountsReceivable 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 customer_number (nullable) is None
        # and model_fields_set contains the field
        if self.customer_number is None and "customer_number" in self.model_fields_set:
            _dict['customerNumber'] = None

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

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "customerId": obj.get("customerId"),
            "customerNumber": obj.get("customerNumber"),
            "name": obj.get("name"),
            "currencyCode": obj.get("currencyCode"),
            "balanceDue": obj.get("balanceDue"),
            "currentAmount": obj.get("currentAmount"),
            "period1Amount": obj.get("period1Amount"),
            "period2Amount": obj.get("period2Amount"),
            "period3Amount": obj.get("period3Amount"),
            "agedAsOfDate": obj.get("agedAsOfDate"),
            "periodLengthFilter": obj.get("periodLengthFilter")
        })
        return _obj


