package com.table.transfer.module.enpty;

import lombok.Data;

import java.math.BigDecimal;
import java.math.RoundingMode;

@Data
public class Trc20TransferInfo {
    private String icon_url;
    private String symbol;
    private String level;
    private String to_address;
    private String tokenType2;
    private String contract_address;
    private String type;
    private int decimals;
    private String name;
    private boolean vip;
    private String tokenType;
    private String from_address;
    private String amount_str;
    private int status;

    /**
     * 【注意】此字段单位为 SUN
     * 请优先使用 {@link #getDecimalsAmount()} 获取 代币 单位余额
     * @deprecated 此方法返回的是未转换的余额，请确认需要的是sun单位
     */
    @Deprecated
    public String getAmount_str() {
        return amount_str;
    }
    public BigDecimal getDecimalsAmount() {
        return new BigDecimal(amount_str).divide(
                BigDecimal.valueOf(Math.pow(10, decimals)),
                decimals,
                RoundingMode.DOWN
        );
    }

    public TransactionInfoDTO Trc20TransferInfo2TransactionInfoDTO(){
        TransactionInfoDTO transactionInfoDTO = new TransactionInfoDTO();
        transactionInfoDTO.setSymbol(symbol);
        transactionInfoDTO.setAmount(getDecimalsAmount());
        transactionInfoDTO.setTokenType(getTokenType());
        transactionInfoDTO.setFromAddress(from_address);
        transactionInfoDTO.setTokenType(tokenType2);
        transactionInfoDTO.setContractAddress(contract_address);
        transactionInfoDTO.setType(type);
        transactionInfoDTO.setDecimals(decimals);
        transactionInfoDTO.setToAddress(to_address);
        return transactionInfoDTO;
    }

}