package com.qqchen.deploy.backend.deploy.service;

import com.qqchen.deploy.backend.deploy.dto.DeployRecordDTO;
import com.qqchen.deploy.backend.deploy.dto.DeployRecordFlowGraphDTO;
import com.qqchen.deploy.backend.deploy.entity.DeployRecord;
import com.qqchen.deploy.backend.workflow.entity.WorkflowInstance;
import com.qqchen.deploy.backend.workflow.enums.WorkflowInstanceStatusEnums;

/**
 * 部署记录服务接口
 *
 * @author qqchen
 * @since 2025-11-02
 */
public interface IDeployRecordService {

    /**
     * 创建部署记录
     *
     * @param workflowInstanceId 工作流实例ID
     * @param businessKey        业务标识
     * @param teamApplicationId  团队应用配置ID
     * @param teamId             团队ID
     * @param applicationId      应用ID
     * @param environmentId      环境ID
     * @param deployBy           部署人
     * @param deployRemark       部署备注
     * @return 部署记录DTO
     */
    DeployRecordDTO createDeployRecord(Long workflowInstanceId, String businessKey, Long teamApplicationId, Long teamId, Long applicationId, Long environmentId, String deployBy, String deployRemark);

    /**
     * 根据工作流实例同步部署记录状态
     *
     * @param instance 工作流实例
     * @param status   工作流状态
     */
    void syncStatusFromWorkflowInstance(WorkflowInstance instance, WorkflowInstanceStatusEnums status);

    /**
     * 根据工作流实例ID查询部署记录
     *
     * @param workflowInstanceId 工作流实例ID
     * @return 部署记录DTO
     */
    DeployRecordDTO findByWorkflowInstanceId(Long workflowInstanceId);

    /**
     * 更新部署记录状态为待审批
     *
     * @param workflowInstanceId 工作流实例ID
     */
    void updateStatusToPendingApproval(Long workflowInstanceId);

    /**
     * 根据审批结果更新部署记录状态
     *
     * @param workflowInstanceId 工作流实例ID
     * @param approved 是否通过审批
     */
    void updateStatusFromApproval(Long workflowInstanceId, boolean approved);

    /**
     * 获取部署记录的流程图数据
     * 包含流程图结构（graph）和节点执行状态（nodeInstances）
     *
     * @param deployRecordId 部署记录ID
     * @return 部署记录流程图DTO
     */
    DeployRecordFlowGraphDTO getDeployFlowGraph(Long deployRecordId);
}

