package com.bizzan.bitrade.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.hibernate.annotations.CreationTimestamp;

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

/**
 * 质押订单，记录用户每次质押的完整生命周期
 *
 * @author auto
 * @date 2026-05-17
 */
@Entity
@Data
@Table(name = "staking_order")
public class StakingOrder {

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

    /** 用户ID */
    @Column(nullable = false, columnDefinition = "bigint comment '用户ID'")
    private Long memberId;

    /** 关联质押配置ID */
    @Column(columnDefinition = "bigint comment '质押配置ID'")
    private Long configId;

    /** 质押币种 */
    @Column(nullable = false, length = 50, columnDefinition = "varchar(50) comment '质押币种'")
    private String coinUnit;

    /** 质押总金额 */
    @Column(columnDefinition = "decimal(26,8) default 0 comment '质押总金额'")
    private BigDecimal amount = BigDecimal.ZERO;

    /** 已释放金额 */
    @Column(columnDefinition = "decimal(26,8) default 0 comment '已释放金额'")
    private BigDecimal releasedAmount = BigDecimal.ZERO;

    /**
     * 质押订单状态
     * 0=质押中（锁定期内，不可提取）
     * 1=解冻释放中（锁定期已到，按配置周期释放）
     * 2=已完成（全部释放完毕）
     */
    @Column(columnDefinition = "int default 0 comment '状态：0质押中 1解冻释放中 2已完成'")
    private Integer status = 0;

    /** 质押开始时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(columnDefinition = "datetime comment '质押开始时间'")
    private Date stakingTime;

    /** 到期解冻时间（stakingTime + lockDays） */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(columnDefinition = "datetime comment '到期解冻时间'")
    private Date unlockTime;

    /** 上次释放时间（分批释放时用于计算下次释放时机） */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(columnDefinition = "datetime comment '上次释放时间'")
    private Date lastReleaseTime;

    /** 创建时间 */
    @CreationTimestamp
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;
}
