# coding: utf-8

"""
    CryptoAPIs

    Crypto APIs is a complex and innovative infrastructure layer that radically simplifies the development of any Blockchain and Crypto related applications. Organized around REST, Crypto APIs can assist both novice Bitcoin/Ethereum enthusiasts and crypto experts with the development of their blockchain applications. Crypto APIs provides unified endpoints and data, raw data, automatic tokens and coins forwardings, callback functionalities, and much more.  # noqa: E501

    The version of the OpenAPI document: 2021-03-20
    Contact: developers@cryptoapis.io
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""


from __future__ import annotations
import pprint
import re  # noqa: F401
import json


from typing import List, Optional
from pydantic import BaseModel, Field, StrictInt, StrictStr, conlist
from cryptoapis.models.decode_raw_transaction_hex_risb_vin_inner import DecodeRawTransactionHexRISBVinInner
from cryptoapis.models.decode_raw_transaction_hex_risb_vout_inner import DecodeRawTransactionHexRISBVoutInner

class DecodeRawTransactionHexRISB(BaseModel):
    """
    Bitcoin
    """
    locktime: StrictInt = Field(..., description="Represents the time at which a particular transaction can be added to the blockchain.")
    transaction_hash: StrictStr = Field(..., alias="transactionHash", description="Represents the same as transactionId for account-based protocols like Ethereum, while it could be different in UTXO-based protocols like Bitcoin. E.g., in UTXO-based protocols hash is different from transactionId for SegWit transactions.")
    v_size: StrictInt = Field(..., alias="vSize", description="Represents the virtual size of this transaction.")
    version: StrictInt = Field(..., description="Represents the transaction version number.")
    vin: conlist(DecodeRawTransactionHexRISBVinInner) = Field(..., description="Represents the transaction inputs.")
    vout: conlist(DecodeRawTransactionHexRISBVoutInner) = Field(..., description="Represents the transaction outputs.")
    weight: Optional[StrictInt] = Field(None, description="Represents the size of Bitcoin block, measured in weight units and including the segwit discount.")
    __properties = ["locktime", "transactionHash", "vSize", "version", "vin", "vout", "weight"]

    class Config:
        """Pydantic configuration"""
        allow_population_by_field_name = True
        validate_assignment = True

    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.dict(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> DecodeRawTransactionHexRISB:
        """Create an instance of DecodeRawTransactionHexRISB from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self):
        """Returns the dictionary representation of the model using alias"""
        _dict = self.dict(by_alias=True,
                          exclude={
                          },
                          exclude_none=True)
        # override the default output from pydantic by calling `to_dict()` of each item in vin (list)
        _items = []
        if self.vin:
            for _item in self.vin:
                if _item:
                    _items.append(_item.to_dict())
            _dict['vin'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in vout (list)
        _items = []
        if self.vout:
            for _item in self.vout:
                if _item:
                    _items.append(_item.to_dict())
            _dict['vout'] = _items
        return _dict

    @classmethod
    def from_dict(cls, obj: dict) -> DecodeRawTransactionHexRISB:
        """Create an instance of DecodeRawTransactionHexRISB from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return DecodeRawTransactionHexRISB.parse_obj(obj)

        _obj = DecodeRawTransactionHexRISB.parse_obj({
            "locktime": obj.get("locktime"),
            "transaction_hash": obj.get("transactionHash"),
            "v_size": obj.get("vSize"),
            "version": obj.get("version"),
            "vin": [DecodeRawTransactionHexRISBVinInner.from_dict(_item) for _item in obj.get("vin")] if obj.get("vin") is not None else None,
            "vout": [DecodeRawTransactionHexRISBVoutInner.from_dict(_item) for _item in obj.get("vout")] if obj.get("vout") is not None else None,
            "weight": obj.get("weight")
        })
        return _obj

