package com.zcxk.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.ToString;

import java.awt.image.BufferedImage;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 验证码图片
 */
@Data
@ToString
@AllArgsConstructor
public class ImageCode implements Serializable {

    private static final long serialVersionUID = -5390786701941159803L;

    private BufferedImage image;
    private String code;
    private LocalDateTime expireTime;

    public ImageCode(BufferedImage image, String code, int expireInt) {
        this.image = image;
        this.code = code;
        this.expireTime = LocalDateTime.now().plusSeconds(expireInt);
    }

    /**
     * 是否过期
     * @return
     */
    public boolean isExpried() {
        return LocalDateTime.now().isAfter(expireTime);
    }
}
