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

class PostPurchaseInvoiceRequest(BaseModel):
    """
    PostPurchaseInvoiceRequest
    """ # noqa: E501
    id: Optional[StrictStr] = Field(default=None, description="(v1.0) The id property for the Dynamics 365 Business Central purchaseInvoice entity")
    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 purchaseInvoice entity")
    invoice_date: Optional[datetime] = Field(default=None, description="(v1.0) The invoiceDate property for the Dynamics 365 Business Central purchaseInvoice entity", alias="invoiceDate")
    due_date: Optional[datetime] = Field(default=None, description="(v1.0) The dueDate property for the Dynamics 365 Business Central purchaseInvoice entity", alias="dueDate")
    vendor_invoice_number: Optional[Annotated[str, Field(strict=True, max_length=35)]] = Field(default=None, description="(v1.0) The vendorInvoiceNumber property for the Dynamics 365 Business Central purchaseInvoice entity", alias="vendorInvoiceNumber")
    vendor_id: Optional[StrictStr] = Field(default=None, description="(v1.0) The vendorId property for the Dynamics 365 Business Central purchaseInvoice entity", alias="vendorId")
    vendor_number: Optional[Annotated[str, Field(strict=True, max_length=20)]] = Field(default=None, description="(v1.0) The vendorNumber property for the Dynamics 365 Business Central purchaseInvoice entity", alias="vendorNumber")
    vendor_name: Optional[Annotated[str, Field(strict=True, max_length=100)]] = Field(default=None, description="(v1.0) The vendorName property for the Dynamics 365 Business Central purchaseInvoice entity", alias="vendorName")
    pay_to_name: Optional[Annotated[str, Field(strict=True, max_length=100)]] = Field(default=None, description="(v1.0) The payToName property for the Dynamics 365 Business Central purchaseInvoice entity", alias="payToName")
    pay_to_contact: Optional[Annotated[str, Field(strict=True, max_length=100)]] = Field(default=None, description="(v1.0) The payToContact property for the Dynamics 365 Business Central purchaseInvoice entity", alias="payToContact")
    pay_to_vendor_id: Optional[StrictStr] = Field(default=None, description="(v1.0) The payToVendorId property for the Dynamics 365 Business Central purchaseInvoice entity", alias="payToVendorId")
    pay_to_vendor_number: Optional[Annotated[str, Field(strict=True, max_length=20)]] = Field(default=None, description="(v1.0) The payToVendorNumber property for the Dynamics 365 Business Central purchaseInvoice entity", alias="payToVendorNumber")
    ship_to_name: Optional[Annotated[str, Field(strict=True, max_length=100)]] = Field(default=None, description="(v1.0) The shipToName property for the Dynamics 365 Business Central purchaseInvoice entity", alias="shipToName")
    ship_to_contact: Optional[Annotated[str, Field(strict=True, max_length=100)]] = Field(default=None, description="(v1.0) The shipToContact property for the Dynamics 365 Business Central purchaseInvoice entity", alias="shipToContact")
    buy_from_address: Optional[Postaladdresstype] = Field(default=None, alias="buyFromAddress")
    pay_to_address: Optional[Postaladdresstype] = Field(default=None, alias="payToAddress")
    ship_to_address: Optional[Postaladdresstype] = Field(default=None, alias="shipToAddress")
    currency_id: Optional[StrictStr] = Field(default=None, description="(v1.0) The currencyId property for the Dynamics 365 Business Central purchaseInvoice entity", alias="currencyId")
    currency_code: Optional[StrictStr] = Field(default=None, description="(v1.0) The currencyCode property for the Dynamics 365 Business Central purchaseInvoice entity", alias="currencyCode")
    prices_include_tax: Optional[StrictBool] = Field(default=None, description="(v1.0) The pricesIncludeTax property for the Dynamics 365 Business Central purchaseInvoice entity", alias="pricesIncludeTax")
    discount_amount: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="(v1.0) The discountAmount property for the Dynamics 365 Business Central purchaseInvoice entity", alias="discountAmount")
    discount_applied_before_tax: Optional[StrictBool] = Field(default=None, description="(v1.0) The discountAppliedBeforeTax property for the Dynamics 365 Business Central purchaseInvoice entity", alias="discountAppliedBeforeTax")
    total_amount_excluding_tax: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="(v1.0) The totalAmountExcludingTax property for the Dynamics 365 Business Central purchaseInvoice entity", alias="totalAmountExcludingTax")
    total_tax_amount: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="(v1.0) The totalTaxAmount property for the Dynamics 365 Business Central purchaseInvoice entity", alias="totalTaxAmount")
    total_amount_including_tax: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="(v1.0) The totalAmountIncludingTax property for the Dynamics 365 Business Central purchaseInvoice entity", alias="totalAmountIncludingTax")
    status: Optional[StrictStr] = Field(default=None, description="(v1.0) The status property for the Dynamics 365 Business Central purchaseInvoice entity")
    last_modified_date_time: Optional[datetime] = Field(default=None, description="(v1.0) The lastModifiedDateTime property for the Dynamics 365 Business Central purchaseInvoice entity", alias="lastModifiedDateTime")
    __properties: ClassVar[List[str]] = ["id", "number", "invoiceDate", "dueDate", "vendorInvoiceNumber", "vendorId", "vendorNumber", "vendorName", "payToName", "payToContact", "payToVendorId", "payToVendorNumber", "shipToName", "shipToContact", "buyFromAddress", "payToAddress", "shipToAddress", "currencyId", "currencyCode", "pricesIncludeTax", "discountAmount", "discountAppliedBeforeTax", "totalAmountExcludingTax", "totalTaxAmount", "totalAmountIncludingTax", "status", "lastModifiedDateTime"]

    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 PostPurchaseInvoiceRequest 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 buy_from_address
        if self.buy_from_address:
            _dict['buyFromAddress'] = self.buy_from_address.to_dict()
        # override the default output from pydantic by calling `to_dict()` of pay_to_address
        if self.pay_to_address:
            _dict['payToAddress'] = self.pay_to_address.to_dict()
        # override the default output from pydantic by calling `to_dict()` of ship_to_address
        if self.ship_to_address:
            _dict['shipToAddress'] = self.ship_to_address.to_dict()
        # set to None if number (nullable) is None
        # and model_fields_set contains the field
        if self.number is None and "number" in self.model_fields_set:
            _dict['number'] = None

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        # set to None if currency_id (nullable) is None
        # and model_fields_set contains the field
        if self.currency_id is None and "currency_id" in self.model_fields_set:
            _dict['currencyId'] = 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 prices_include_tax (nullable) is None
        # and model_fields_set contains the field
        if self.prices_include_tax is None and "prices_include_tax" in self.model_fields_set:
            _dict['pricesIncludeTax'] = None

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

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

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of PostPurchaseInvoiceRequest 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"),
            "invoiceDate": obj.get("invoiceDate"),
            "dueDate": obj.get("dueDate"),
            "vendorInvoiceNumber": obj.get("vendorInvoiceNumber"),
            "vendorId": obj.get("vendorId"),
            "vendorNumber": obj.get("vendorNumber"),
            "vendorName": obj.get("vendorName"),
            "payToName": obj.get("payToName"),
            "payToContact": obj.get("payToContact"),
            "payToVendorId": obj.get("payToVendorId"),
            "payToVendorNumber": obj.get("payToVendorNumber"),
            "shipToName": obj.get("shipToName"),
            "shipToContact": obj.get("shipToContact"),
            "buyFromAddress": Postaladdresstype.from_dict(obj["buyFromAddress"]) if obj.get("buyFromAddress") is not None else None,
            "payToAddress": Postaladdresstype.from_dict(obj["payToAddress"]) if obj.get("payToAddress") is not None else None,
            "shipToAddress": Postaladdresstype.from_dict(obj["shipToAddress"]) if obj.get("shipToAddress") is not None else None,
            "currencyId": obj.get("currencyId"),
            "currencyCode": obj.get("currencyCode"),
            "pricesIncludeTax": obj.get("pricesIncludeTax"),
            "discountAmount": obj.get("discountAmount"),
            "discountAppliedBeforeTax": obj.get("discountAppliedBeforeTax"),
            "totalAmountExcludingTax": obj.get("totalAmountExcludingTax"),
            "totalTaxAmount": obj.get("totalTaxAmount"),
            "totalAmountIncludingTax": obj.get("totalAmountIncludingTax"),
            "status": obj.get("status"),
            "lastModifiedDateTime": obj.get("lastModifiedDateTime")
        })
        return _obj


