package com.qqchen.deploy.backend.workflow.entity;

import com.qqchen.deploy.backend.framework.domain.Entity;
import com.qqchen.deploy.backend.workflow.dto.definition.workflow.WorkflowDefinitionGraph;
import com.qqchen.deploy.backend.workflow.entity.converter.WorkflowGraphType;
import com.qqchen.deploy.backend.workflow.enums.WorkflowInstanceStatusEnums;
import jakarta.persistence.Column;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.Type;

import java.time.LocalDateTime;

/**
 * 工作流实例实体
 */
@Data
@Table(name = "workflow_instance")
@jakarta.persistence.Entity
@EqualsAndHashCode(callSuper = true)
public class WorkflowInstance extends Entity<Long> {
    
    /**
     * 流程实例ID
     */
    @Column(name = "process_instance_id", nullable = false)
    private String processInstanceId;
    
    /**
     * 流程定义ID
     */
    @Column(name = "process_definition_id", nullable = false)
    private String processDefinitionId;

    @Column(name = "workflow_definition_id", nullable = false)
    private Long  workflowDefinitionId;
    
    /**
     * 业务标识
     */
    @Column(name = "business_key")
    private String businessKey;
    
    /**
     * 启动表单数据ID（外键关联form_data）
     */
    @Column(name = "form_data_id")
    private Long formDataId;
    
    /**
     * 实例状态
     */
    @Column(nullable = false)
    @Enumerated(EnumType.STRING)
    private WorkflowInstanceStatusEnums status;
    
    /**
     * 流程变量(JSON)
     */
    @Column(columnDefinition = "TEXT")
    private String variables;
    
    /**
     * 流程图数据快照（启动时保存，用于画布还原）
     */
    @Type(WorkflowGraphType.class)
    @Column(name = "graph_snapshot", columnDefinition = "json")
    private WorkflowDefinitionGraph graphSnapshot;
    
    /**
     * 开始时间
     */
    @Column(name = "start_time")
    private LocalDateTime startTime;
    
    /**
     * 结束时间
     */
    @Column(name = "end_time")
    private LocalDateTime endTime;
}
