# 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, StrictBytes, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Tuple, Union
from typing_extensions import Annotated
from pybusinesscentral.model.general_ledger_entry import GeneralLedgerEntry
from typing import Optional, Set
from typing_extensions import Self

class GeneralLedgerEntryAttachments(BaseModel):
    """
    GeneralLedgerEntryAttachments
    """ # noqa: E501
    general_ledger_entry_number: Optional[StrictInt] = Field(default=None, description="(v1.0) The generalLedgerEntryNumber property for the Dynamics 365 Business Central generalLedgerEntryAttachments entity", alias="generalLedgerEntryNumber")
    id: Optional[StrictStr] = Field(default=None, description="(v1.0) The id property for the Dynamics 365 Business Central generalLedgerEntryAttachments entity")
    file_name: Optional[Annotated[str, Field(strict=True, max_length=250)]] = Field(default=None, description="(v1.0) The fileName property for the Dynamics 365 Business Central generalLedgerEntryAttachments entity", alias="fileName")
    byte_size: Optional[StrictInt] = Field(default=None, description="(v1.0) The byteSize property for the Dynamics 365 Business Central generalLedgerEntryAttachments entity", alias="byteSize")
    content: Optional[Union[StrictBytes, StrictStr, Tuple[StrictStr, StrictBytes]]] = Field(default=None, description="(v1.0) The content property for the Dynamics 365 Business Central generalLedgerEntryAttachments entity")
    created_date_time: Optional[datetime] = Field(default=None, description="(v1.0) The createdDateTime property for the Dynamics 365 Business Central generalLedgerEntryAttachments entity", alias="createdDateTime")
    general_ledger_entry: Optional[GeneralLedgerEntry] = Field(default=None, alias="generalLedgerEntry")
    __properties: ClassVar[List[str]] = ["generalLedgerEntryNumber", "id", "fileName", "byteSize", "content", "createdDateTime", "generalLedgerEntry"]

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "generalLedgerEntryNumber": obj.get("generalLedgerEntryNumber"),
            "id": obj.get("id"),
            "fileName": obj.get("fileName"),
            "byteSize": obj.get("byteSize"),
            "content": obj.get("content"),
            "createdDateTime": obj.get("createdDateTime"),
            "generalLedgerEntry": GeneralLedgerEntry.from_dict(obj["generalLedgerEntry"]) if obj.get("generalLedgerEntry") is not None else None
        })
        return _obj


