package com.purui.prims.dscheduler.model;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.purui.prims.dscheduler.enums.ConditionType;
import lombok.Data;

import java.util.Date;

@Data
public class ProcessTaskRelation {

    // id
    private Integer id;

    // 名称
    private String name;

    // 工作流定义
    private int processDefinitionVersion;

    // 工作流定义编号
    private long processDefinitionCode;

    // 前置任务编号
    private long preTaskCode;

    // 前置任务版本
    private int preTaskVersion;

    // 发布任务编号
    private long postTaskCode;

    // 发布任务版本
    private int postTaskVersion;

    // 条件类型
    private ConditionType conditionType;

    // 条件参数
    private Object conditionParams;

    // 创建时间
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    // 更新时间
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;

    public static ProcessTaskRelation generateProcessTaskRelation(TaskDefinition preTask, TaskDefinition postTask) {
        if (preTask == null) {
            preTask = new TaskDefinition();
            preTask.setCode(0L);
        }
        if (postTask == null) {
            postTask = new TaskDefinition();
            postTask.setCode(0L);
        }
        if (preTask.getVersion() == null) {
            preTask.setVersion(0);
        }
        if (postTask.getVersion() == null) {
            postTask.setVersion(0);
        }
        ProcessTaskRelation processTaskRelation = new ProcessTaskRelation();
        processTaskRelation.setName("");
        processTaskRelation.setPreTaskCode(preTask.getCode());
        processTaskRelation.setPreTaskVersion(preTask.getVersion());
        processTaskRelation.setPostTaskCode(postTask.getCode());
        processTaskRelation.setPostTaskVersion(postTask.getVersion());
        processTaskRelation.setConditionType(ConditionType.NONE);
        processTaskRelation.setConditionParams(new Object());
        return processTaskRelation;
    }
}
