# 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, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from pybusinesscentral.model.account import Account
from pybusinesscentral.model.dimension import Dimension
from pybusinesscentral.model.dimension_value import DimensionValue
from typing import Optional, Set
from typing_extensions import Self

class DefaultDimensions(BaseModel):
    """
    DefaultDimensions
    """ # noqa: E501
    parent_id: Optional[StrictStr] = Field(default=None, description="(v1.0) The parentId property for the Dynamics 365 Business Central defaultDimensions entity", alias="parentId")
    dimension_id: Optional[StrictStr] = Field(default=None, description="(v1.0) The dimensionId property for the Dynamics 365 Business Central defaultDimensions entity", alias="dimensionId")
    dimension_code: Optional[Annotated[str, Field(strict=True, max_length=20)]] = Field(default=None, description="(v1.0) The dimensionCode property for the Dynamics 365 Business Central defaultDimensions entity", alias="dimensionCode")
    dimension_value_id: Optional[StrictStr] = Field(default=None, description="(v1.0) The dimensionValueId property for the Dynamics 365 Business Central defaultDimensions entity", alias="dimensionValueId")
    dimension_value_code: Optional[Annotated[str, Field(strict=True, max_length=20)]] = Field(default=None, description="(v1.0) The dimensionValueCode property for the Dynamics 365 Business Central defaultDimensions entity", alias="dimensionValueCode")
    posting_validation: Optional[StrictStr] = Field(default=None, description="(v1.0) The postingValidation property for the Dynamics 365 Business Central defaultDimensions entity", alias="postingValidation")
    account: Optional[Account] = None
    dimension: Optional[Dimension] = None
    dimension_value: Optional[DimensionValue] = Field(default=None, alias="dimensionValue")
    __properties: ClassVar[List[str]] = ["parentId", "dimensionId", "dimensionCode", "dimensionValueId", "dimensionValueCode", "postingValidation", "account", "dimension", "dimensionValue"]

    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 DefaultDimensions 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()
        # override the default output from pydantic by calling `to_dict()` of dimension
        if self.dimension:
            _dict['dimension'] = self.dimension.to_dict()
        # override the default output from pydantic by calling `to_dict()` of dimension_value
        if self.dimension_value:
            _dict['dimensionValue'] = self.dimension_value.to_dict()
        # set to None if dimension_code (nullable) is None
        # and model_fields_set contains the field
        if self.dimension_code is None and "dimension_code" in self.model_fields_set:
            _dict['dimensionCode'] = None

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "parentId": obj.get("parentId"),
            "dimensionId": obj.get("dimensionId"),
            "dimensionCode": obj.get("dimensionCode"),
            "dimensionValueId": obj.get("dimensionValueId"),
            "dimensionValueCode": obj.get("dimensionValueCode"),
            "postingValidation": obj.get("postingValidation"),
            "account": Account.from_dict(obj["account"]) if obj.get("account") is not None else None,
            "dimension": Dimension.from_dict(obj["dimension"]) if obj.get("dimension") is not None else None,
            "dimensionValue": DimensionValue.from_dict(obj["dimensionValue"]) if obj.get("dimensionValue") is not None else None
        })
        return _obj


