# 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 pybusinesscentral.model.general_ledger_entry_dimensions_inner import GeneralLedgerEntryDimensionsInner
from pybusinesscentral.model.project import Project
from pybusinesscentral.model.unitofmeasuretype import Unitofmeasuretype
from typing import Optional, Set
from typing_extensions import Self

class TimeRegistrationEntry(BaseModel):
    """
    TimeRegistrationEntry
    """ # noqa: E501
    id: Optional[StrictStr] = Field(default=None, description="(v1.0) The id property for the Dynamics 365 Business Central timeRegistrationEntry entity")
    employee_id: Optional[StrictStr] = Field(default=None, description="(v1.0) The employeeId property for the Dynamics 365 Business Central timeRegistrationEntry entity", alias="employeeId")
    employee_number: Optional[Annotated[str, Field(strict=True, max_length=20)]] = Field(default=None, description="(v1.0) The employeeNumber property for the Dynamics 365 Business Central timeRegistrationEntry entity", alias="employeeNumber")
    job_id: Optional[StrictStr] = Field(default=None, description="(v1.0) The jobId property for the Dynamics 365 Business Central timeRegistrationEntry entity", alias="jobId")
    job_number: Optional[Annotated[str, Field(strict=True, max_length=20)]] = Field(default=None, description="(v1.0) The jobNumber property for the Dynamics 365 Business Central timeRegistrationEntry entity", alias="jobNumber")
    absence: Optional[Annotated[str, Field(strict=True, max_length=10)]] = Field(default=None, description="(v1.0) The absence property for the Dynamics 365 Business Central timeRegistrationEntry entity")
    line_number: Optional[StrictInt] = Field(default=None, description="(v1.0) The lineNumber property for the Dynamics 365 Business Central timeRegistrationEntry entity", alias="lineNumber")
    var_date: Optional[datetime] = Field(default=None, description="(v1.0) The date property for the Dynamics 365 Business Central timeRegistrationEntry entity", alias="date")
    quantity: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="(v1.0) The quantity property for the Dynamics 365 Business Central timeRegistrationEntry entity")
    status: Optional[StrictStr] = Field(default=None, description="(v1.0) The status property for the Dynamics 365 Business Central timeRegistrationEntry entity")
    unit_of_measure_id: Optional[StrictStr] = Field(default=None, description="(v1.0) The unitOfMeasureId property for the Dynamics 365 Business Central timeRegistrationEntry entity", alias="unitOfMeasureId")
    unit_of_measure: Optional[Unitofmeasuretype] = Field(default=None, alias="unitOfMeasure")
    dimensions: Optional[List[Optional[GeneralLedgerEntryDimensionsInner]]] = None
    last_modfied_date_time: Optional[datetime] = Field(default=None, description="(v1.0) The lastModfiedDateTime property for the Dynamics 365 Business Central timeRegistrationEntry entity", alias="lastModfiedDateTime")
    project: Optional[Project] = None
    __properties: ClassVar[List[str]] = ["id", "employeeId", "employeeNumber", "jobId", "jobNumber", "absence", "lineNumber", "date", "quantity", "status", "unitOfMeasureId", "unitOfMeasure", "dimensions", "lastModfiedDateTime", "project"]

    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 TimeRegistrationEntry 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 unit_of_measure
        if self.unit_of_measure:
            _dict['unitOfMeasure'] = self.unit_of_measure.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in dimensions (list)
        _items = []
        if self.dimensions:
            for _item_dimensions in self.dimensions:
                if _item_dimensions:
                    _items.append(_item_dimensions.to_dict())
            _dict['dimensions'] = _items
        # override the default output from pydantic by calling `to_dict()` of project
        if self.project:
            _dict['project'] = self.project.to_dict()
        # set to None if employee_id (nullable) is None
        # and model_fields_set contains the field
        if self.employee_id is None and "employee_id" in self.model_fields_set:
            _dict['employeeId'] = None

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

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

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

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

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

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of TimeRegistrationEntry 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"),
            "employeeId": obj.get("employeeId"),
            "employeeNumber": obj.get("employeeNumber"),
            "jobId": obj.get("jobId"),
            "jobNumber": obj.get("jobNumber"),
            "absence": obj.get("absence"),
            "lineNumber": obj.get("lineNumber"),
            "date": obj.get("date"),
            "quantity": obj.get("quantity"),
            "status": obj.get("status"),
            "unitOfMeasureId": obj.get("unitOfMeasureId"),
            "unitOfMeasure": Unitofmeasuretype.from_dict(obj["unitOfMeasure"]) if obj.get("unitOfMeasure") is not None else None,
            "dimensions": [GeneralLedgerEntryDimensionsInner.from_dict(_item) for _item in obj["dimensions"]] if obj.get("dimensions") is not None else None,
            "lastModfiedDateTime": obj.get("lastModfiedDateTime"),
            "project": Project.from_dict(obj["project"]) if obj.get("project") is not None else None
        })
        return _obj


