# coding: utf-8

"""
    Lethean Blockchain API

    OpenAPI for Lethean Blockchain

    The version of the OpenAPI document: 6.0.1
    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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from lthn.models.transaction_attachment_model import TransactionAttachmentModel
from lthn.models.transaction_extra_model import TransactionExtraModel
from lthn.models.transaction_input_model import TransactionInputModel
from lthn.models.transaction_output_model import TransactionOutputModel
from typing import Optional, Set
from typing_extensions import Self

class TransactionDetailsModel(BaseModel):
    """
    TransactionDetailsModel
    """ # noqa: E501
    amount: Optional[StrictInt] = None
    attachments: Optional[List[TransactionAttachmentModel]] = None
    blob: Optional[StrictStr] = None
    blob_size: Optional[StrictInt] = None
    extra: Optional[List[TransactionExtraModel]] = None
    fee: Optional[StrictInt] = None
    id: Optional[StrictStr] = None
    ins: Optional[List[TransactionInputModel]] = None
    keeper_block: Optional[StrictInt] = None
    object_in_json: Optional[StrictStr] = None
    outs: Optional[List[TransactionOutputModel]] = None
    pub_key: Optional[StrictStr] = None
    timestamp: Optional[StrictInt] = None
    __properties: ClassVar[List[str]] = ["amount", "attachments", "blob", "blob_size", "extra", "fee", "id", "ins", "keeper_block", "object_in_json", "outs", "pub_key", "timestamp"]

    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 TransactionDetailsModel 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 attachments (list)
        _items = []
        if self.attachments:
            for _item_attachments in self.attachments:
                if _item_attachments:
                    _items.append(_item_attachments.to_dict())
            _dict['attachments'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in extra (list)
        _items = []
        if self.extra:
            for _item_extra in self.extra:
                if _item_extra:
                    _items.append(_item_extra.to_dict())
            _dict['extra'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in ins (list)
        _items = []
        if self.ins:
            for _item_ins in self.ins:
                if _item_ins:
                    _items.append(_item_ins.to_dict())
            _dict['ins'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in outs (list)
        _items = []
        if self.outs:
            for _item_outs in self.outs:
                if _item_outs:
                    _items.append(_item_outs.to_dict())
            _dict['outs'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "amount": obj.get("amount"),
            "attachments": [TransactionAttachmentModel.from_dict(_item) for _item in obj["attachments"]] if obj.get("attachments") is not None else None,
            "blob": obj.get("blob"),
            "blob_size": obj.get("blob_size"),
            "extra": [TransactionExtraModel.from_dict(_item) for _item in obj["extra"]] if obj.get("extra") is not None else None,
            "fee": obj.get("fee"),
            "id": obj.get("id"),
            "ins": [TransactionInputModel.from_dict(_item) for _item in obj["ins"]] if obj.get("ins") is not None else None,
            "keeper_block": obj.get("keeper_block"),
            "object_in_json": obj.get("object_in_json"),
            "outs": [TransactionOutputModel.from_dict(_item) for _item in obj["outs"]] if obj.get("outs") is not None else None,
            "pub_key": obj.get("pub_key"),
            "timestamp": obj.get("timestamp")
        })
        return _obj


