package com.bizzan.bitrade.entity;

import lombok.Data;

import javax.persistence.*;
import java.util.Date;

@Entity
@Data
@Table(name = "withdraw_chain_config",
        uniqueConstraints = @UniqueConstraint(columnNames = {"coin_unit", "chain_name"}))
public class WithdrawChainConfig {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "coin_unit", nullable = false, length = 20)
    private String coinUnit;

    @Column(name = "chain_name", nullable = false, length = 20)
    private String chainName;

    @Column(name = "rpc_url", nullable = false, length = 256)
    private String rpcUrl;

    @Column(name = "contract_address", nullable = false, length = 128)
    private String contractAddress;

    @Column(name = "payout_address", length = 128)
    private String payoutAddress;

    @Column(name = "currency")
    private Integer currency = 3;

    /** 0=私钥直接存储，1=助记词（BIP44派生） */
    @Column(name = "key_type", nullable = false)
    private Integer keyType = 0;

    @Column(name = "sign_key", columnDefinition = "TEXT", nullable = false)
    private String signKey;

    @Column(name = "derive_path", length = 64)
    private String derivePath;

    /** 1=测试模式（跳过链上验证），0=生产模式 */
    @Column(name = "test_mode", nullable = false)
    private Integer testMode = 0;

    @Column(name = "enabled", nullable = false)
    private Integer enabled = 1;

    @Column(name = "remark", length = 256)
    private String remark;

    @Column(name = "create_time", nullable = false, updatable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date createTime;

    @Column(name = "update_time")
    @Temporal(TemporalType.TIMESTAMP)
    private Date updateTime;

    @PrePersist
    protected void onCreate() {
        createTime = new Date();
        updateTime = new Date();
    }

    @PreUpdate
    protected void onUpdate() {
        updateTime = new Date();
    }
}
