# 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 pydantic import BaseModel, ConfigDict, Field
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from pybusinesscentral.model.currency import Currency
from pybusinesscentral.model.customer_financial_detail import CustomerFinancialDetail
from pybusinesscentral.model.default_dimensions import DefaultDimensions
from pybusinesscentral.model.payment_method import PaymentMethod
from pybusinesscentral.model.payment_term import PaymentTerm
from pybusinesscentral.model.picture import Picture
from pybusinesscentral.model.shipment_method import ShipmentMethod
from typing import Optional, Set
from typing_extensions import Self

class Postaladdresstype(BaseModel):
    """
    Postaladdresstype
    """ # noqa: E501
    street: Optional[Annotated[str, Field(strict=True, max_length=152)]] = Field(default=None, description="(v1.0) The street property for the Dynamics 365 Business Central postaladdresstype entity")
    city: Optional[Annotated[str, Field(strict=True, max_length=30)]] = Field(default=None, description="(v1.0) The city property for the Dynamics 365 Business Central postaladdresstype entity")
    state: Optional[Annotated[str, Field(strict=True, max_length=30)]] = Field(default=None, description="(v1.0) The state property for the Dynamics 365 Business Central postaladdresstype entity")
    country_letter_code: Optional[Annotated[str, Field(strict=True, max_length=10)]] = Field(default=None, description="(v1.0) The countryLetterCode property for the Dynamics 365 Business Central postaladdresstype entity", alias="countryLetterCode")
    postal_code: Optional[Annotated[str, Field(strict=True, max_length=20)]] = Field(default=None, description="(v1.0) The postalCode property for the Dynamics 365 Business Central postaladdresstype entity", alias="postalCode")
    customer_financial_details: Optional[List[CustomerFinancialDetail]] = Field(default=None, alias="customerFinancialDetails")
    picture: Optional[List[Picture]] = None
    default_dimensions: Optional[List[DefaultDimensions]] = Field(default=None, alias="defaultDimensions")
    currency: Optional[Currency] = None
    payment_term: Optional[PaymentTerm] = Field(default=None, alias="paymentTerm")
    shipment_method: Optional[ShipmentMethod] = Field(default=None, alias="shipmentMethod")
    payment_method: Optional[PaymentMethod] = Field(default=None, alias="paymentMethod")
    __properties: ClassVar[List[str]] = ["street", "city", "state", "countryLetterCode", "postalCode", "customerFinancialDetails", "picture", "defaultDimensions", "currency", "paymentTerm", "shipmentMethod", "paymentMethod"]

    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 Postaladdresstype 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 customer_financial_details (list)
        _items = []
        if self.customer_financial_details:
            for _item_customer_financial_details in self.customer_financial_details:
                if _item_customer_financial_details:
                    _items.append(_item_customer_financial_details.to_dict())
            _dict['customerFinancialDetails'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in picture (list)
        _items = []
        if self.picture:
            for _item_picture in self.picture:
                if _item_picture:
                    _items.append(_item_picture.to_dict())
            _dict['picture'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in default_dimensions (list)
        _items = []
        if self.default_dimensions:
            for _item_default_dimensions in self.default_dimensions:
                if _item_default_dimensions:
                    _items.append(_item_default_dimensions.to_dict())
            _dict['defaultDimensions'] = _items
        # override the default output from pydantic by calling `to_dict()` of currency
        if self.currency:
            _dict['currency'] = self.currency.to_dict()
        # override the default output from pydantic by calling `to_dict()` of payment_term
        if self.payment_term:
            _dict['paymentTerm'] = self.payment_term.to_dict()
        # override the default output from pydantic by calling `to_dict()` of shipment_method
        if self.shipment_method:
            _dict['shipmentMethod'] = self.shipment_method.to_dict()
        # override the default output from pydantic by calling `to_dict()` of payment_method
        if self.payment_method:
            _dict['paymentMethod'] = self.payment_method.to_dict()
        # set to None if street (nullable) is None
        # and model_fields_set contains the field
        if self.street is None and "street" in self.model_fields_set:
            _dict['street'] = None

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

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "street": obj.get("street"),
            "city": obj.get("city"),
            "state": obj.get("state"),
            "countryLetterCode": obj.get("countryLetterCode"),
            "postalCode": obj.get("postalCode"),
            "customerFinancialDetails": [CustomerFinancialDetail.from_dict(_item) for _item in obj["customerFinancialDetails"]] if obj.get("customerFinancialDetails") is not None else None,
            "picture": [Picture.from_dict(_item) for _item in obj["picture"]] if obj.get("picture") is not None else None,
            "defaultDimensions": [DefaultDimensions.from_dict(_item) for _item in obj["defaultDimensions"]] if obj.get("defaultDimensions") is not None else None,
            "currency": Currency.from_dict(obj["currency"]) if obj.get("currency") is not None else None,
            "paymentTerm": PaymentTerm.from_dict(obj["paymentTerm"]) if obj.get("paymentTerm") is not None else None,
            "shipmentMethod": ShipmentMethod.from_dict(obj["shipmentMethod"]) if obj.get("shipmentMethod") is not None else None,
            "paymentMethod": PaymentMethod.from_dict(obj["paymentMethod"]) if obj.get("paymentMethod") is not None else None
        })
        return _obj


