package jnpf.model.certificate.vo.app;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import jnpf.util.StringUtil;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

/**
 * 健康证明细。
 */
@Data
@NoArgsConstructor
public class HealthCertificateVO implements Serializable {

    private static final long serialVersionUID = 1L;

    public static HealthCertificateVO of (HealthCertificateDetailVO healthCertificateDetailVO) {
        return new HealthCertificateVO(healthCertificateDetailVO.getUserId(),
                healthCertificateDetailVO.getCertificateInstanceId(),
                healthCertificateDetailVO.getCertificateImage(),
                healthCertificateDetailVO.getIssueDate(),
                healthCertificateDetailVO.getExpireDate(),
                healthCertificateDetailVO.getStatus());
    }

    public HealthCertificateVO(String userId, String certificateInstanceId, String certificateImage, Date issueDate, Date expireDate, Integer status) {
        this.userId = userId;
        this.certificateInstanceId = certificateInstanceId;
        if(StringUtil.isBlank(certificateImage)){
            certificateImage = "[]";
        }
        this.certificateImage = certificateImage;
        if(Objects.isNull(issueDate)){
            this.issueDate = 0L;
        }else{
            this.issueDate = issueDate.getTime();
        }
        if(Objects.isNull(expireDate)){
            this.expireDate = 0L;
        }else{
            this.expireDate = expireDate.getTime();
        }
        this.status = status;
    }

    /**
     * 员工用户ID。
     */
    private String userId;
    /**
     * 证照实例ID。
     */
    private String certificateInstanceId;

    /**
     * 健康证图片。
     */
    private String certificateImage;

    /**
     * 发证日期。格式为时间戳
     */
    private Long issueDate;

    /**
     * 到期日期。格式为时间戳
     */
    private Long expireDate;

    /**
     * 状态：1-缺失，2-过期，3-临期，4-正常。
     */
    private Integer status;
}

