package cn.axzo.msg.center.message.service.todo.cache;

import cn.axzo.msg.center.service.pending.response.PendingMessageStatisticResponseV2;
import cn.axzo.msg.center.utils.DateFormatUtil;
import lombok.Data;

import java.util.Date;
import java.util.Objects;

/**
 * @author yanglin
 */
@Data
class NodeStatCacheValue {

    private Date templateLatestUpdateTime;
    private Date todoLatestUpdateTime;
    private String templateLatestUpdateTimeStr;
    private String todoLatestUpdateTimeStr;
    private PendingMessageStatisticResponseV2 response;

    boolean shouldReload(Date templateLatestUpdateTime, Date todoLatestUpdateTime) {
        return !Objects.equals(this.templateLatestUpdateTime, templateLatestUpdateTime)
                || !Objects.equals(this.todoLatestUpdateTime, todoLatestUpdateTime);
    }

    public void setTemplateLatestUpdateTime(Date templateLatestUpdateTime) {
        this.templateLatestUpdateTime = templateLatestUpdateTime;
        this.templateLatestUpdateTimeStr = DateFormatUtil.toReadableString(templateLatestUpdateTime);
    }

    public void setTodoLatestUpdateTime(Date todoLatestUpdateTime) {
        this.todoLatestUpdateTime = todoLatestUpdateTime;
        this.todoLatestUpdateTimeStr = DateFormatUtil.toReadableString(todoLatestUpdateTime);
    }

}