package com.lanyuanxiaoyao.service.scheduler.strategy;

import cn.hutool.core.util.ObjectUtil;

/**
 * @author ZhangJiacheng
 * @date 2023-06-26
 */
public class ScheduleStrategyVO {
    private final String name;
    private final String comment;
    private final String job;
    private final String trigger;
    private final Long lastFireTime;
    private final Long nextFireTime;

    public ScheduleStrategyVO(String name, String comment, String job, String trigger, Long lastFireTime, Long nextFireTime) {
        this.name = name;
        this.comment = comment;
        this.job = job;
        this.trigger = trigger;
        this.lastFireTime = lastFireTime;
        this.nextFireTime = nextFireTime;
    }

    public ScheduleStrategyVO(ScheduleStrategy strategy) {
        this(
                strategy.name(),
                strategy.comment(),
                strategy.job().getDescription(),
                strategy.trigger().getDescription(),
                ObjectUtil.isNull(strategy.trigger().getPreviousFireTime()) ? 0 : strategy.trigger().getPreviousFireTime().getTime(),
                ObjectUtil.isNull(strategy.trigger().getNextFireTime()) ? 0 : strategy.trigger().getNextFireTime().getTime()
        );
    }

    public String getName() {
        return name;
    }

    public String getComment() {
        return comment;
    }

    public String getJob() {
        return job;
    }

    public String getTrigger() {
        return trigger;
    }

    public Long getLastFireTime() {
        return lastFireTime;
    }

    public Long getNextFireTime() {
        return nextFireTime;
    }

    @Override
    public String toString() {
        return "ScheduleStrategyVO{" +
               "name='" + name + '\'' +
               ", comment='" + comment + '\'' +
               ", job='" + job + '\'' +
               ", trigger='" + trigger + '\'' +
               ", lastFireTime=" + lastFireTime +
               ", nextFireTime=" + nextFireTime +
               '}';
    }
}
