package com.foreverwin.mesnac.quartz.dto;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.foreverwin.mesnac.quartz.model.SystemJob;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

/**
 * @author Ervin Chen
 * @date 2020/10/21 10:38
 */
@JsonIgnoreProperties(ignoreUnknown=true)
public class SystemJobDTO extends SystemJob {

    private String jobName;

    private String jobGroup;

    private String cronExpression;

    private LocalDateTime prevFireTime;

    private LocalDateTime nextFireTime;

    private LocalDateTime startTime;

    private String triggerState;

    public String getJobName() {
        return jobName;
    }

    public void setJobName(String jobName) {
        this.jobName = jobName;
    }

    public String getJobGroup() {
        return jobGroup;
    }

    public void setJobGroup(String jobGroup) {
        this.jobGroup = jobGroup;
    }

    public String getCronExpression() {
        return cronExpression;
    }

    public void setCronExpression(String cronExpression) {
        this.cronExpression = cronExpression;
    }

    public LocalDateTime getPrevFireTime() {
        return prevFireTime;
    }

    public void setPrevFireTime(Long prevFireTime) {
        if(prevFireTime != null && prevFireTime > 0){
            Date date = new Date();
            date.setTime(prevFireTime);
            LocalDateTime localDateTime = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
            this.prevFireTime = localDateTime;
        }
    }

    public LocalDateTime getNextFireTime() {
        return nextFireTime;
    }

    public void setNextFireTime(Long nextFireTime) {
        if(nextFireTime != null && nextFireTime > 0){
            Date date = new Date();
            date.setTime(nextFireTime);
            LocalDateTime localDateTime = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
            this.nextFireTime = localDateTime;
        }
    }

    public LocalDateTime getStartTime() {
        return startTime;
    }

    public void setStartTime(Long startTime) {
        if(startTime != null && startTime > 0){
            Date date = new Date();
            date.setTime(startTime);
            LocalDateTime localDateTime = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
            this.startTime = localDateTime;
        }
    }

    public String getTriggerState() {
        return triggerState;
    }

    public void setTriggerState(String triggerState) {
        this.triggerState = triggerState;
    }
}
