package com.ssyf.common.security.domain;

import com.ssyf.common.security.constant.SecurityConstant;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * <p>证书类</p>
 * <p>某事件的有效证明信息</p>
 * @author huwei
 * @date 2023/9/24 15:47
 */
@Data
@Accessors(chain = true)
public class Certificate<T> {

    /**
     * 证书类型
     */
    private String type;

    /**
     * 事件源
     * 示例：
     * 1. 手机验证码证书，event为验证手机
     * 2. 邮箱验证码证书，event为验证邮箱
     *
     */
    private String event;

    /**
     * 事件内容/证书内容
     * 示例：
     * 1. 手机验证码证书，content为当前手机的验证码
     * 2. 邮箱验证码证书，content为当前手机的验证码
     */
    private T content;

    /**
     * 签证时间戳
     */
    private long startTimeMillis = System.currentTimeMillis();

    /**
     * 到期时间戳
     */
    private long endTimeMillis;

    public Certificate(){}

    public Certificate( String type, String event,T content) {
        this(type ,event ,content , SecurityConstant.CERTIFICATE_TIMEOUT_MILLIS);
    }

    public Certificate(String type ,String event ,T content, long timeoutMillis) {
        this.event = event;
        this.type = type;
        this.content = content;
        this.endTimeMillis = startTimeMillis + timeoutMillis;
    }
}
