package com.table.transfer.module.enpty;

import cn.hutool.core.util.StrUtil;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import lombok.Data;

import java.math.BigInteger;


@Data
public class TransferRequest {
    /**
     * 请求方自己携带的用于区分的id
     */
    private String requestId;
    @NotBlank(message = "链类型不能为空")
    private String chain; // ETH, BSC, TRON
    @NotBlank(message = "链类型不能为空")
    private String coin; // ETH, BSC, TRON

    private String privateKey;
    @NotBlank(message = "加密私钥不能为空")
    private String encryptionPrivateKey;
    @NotBlank(message = "发送地址不能为空")
    private String fromAddress;
    @NotBlank(message = "接收地址不能为空")
    private String toAddress;

    @NotBlank(message = "转账金额不能为空")
    @Pattern(regexp = "^[0-9]+(\\.[0-9]+)?$", message = "金额格式不正确")
    private String amount;
    private BigInteger amountWei;
    private String contractAddress; // 代币合约地址，为空表示主币转账

    @Pattern(regexp = "^[0-9]*$", message = "Gas Limit必须为数字")
    private String gasLimit;

    @Pattern(regexp = "^[0-9]+(\\.[0-9]+)?$", message = "Gas Price格式不正确")
    private String gasPrice;

    public String getAssetCode() {
        return coin + "-" + chain;
    }

    public boolean isTokenTransfer() {
       return !StrUtil.equalsAnyIgnoreCase(getAssetCode(), "ETH-ETH", "BNB-BSC", "TRX-TRON");
    }
}