package com.ruoyi.interfaces.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.utils.JsonUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * entity:MdModelWorkflowExecution
 *
 * @author lql
 * @date 2025-7-15
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName
public class MdModelWorkflowExecution implements Serializable {

    public enum ExecutionStatus {
        PENDING, RUNNING, SUCCESS, FAILED, SKIPPED, RETRYING
    }

    @TableId
    private Long id;
    @ApiModelProperty("工作流ID")
    private Long workflowId;
    @ApiModelProperty("状态")
    private ExecutionStatus status;
    @ApiModelProperty("执行输入")
    private String input;
    @ApiModelProperty("最终输出")
    private String output;
    @ApiModelProperty("执行上下文")
    private String context;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty("开始时间")
    private Date startTime;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty("结束时间")
    private Date endTime;

    @TableField(exist = false)
    @ApiModelProperty("步骤列表")
    private List<MdModelStepExecution> stepExecutions;

    public void setOutput(Map<String, Object> output) {
        this.output = JsonUtils.objectToJson(output);
    }

}
