/**
 * 플로우 관리 라우터
 */

import { Router } from "express";
import { FlowController } from "../controllers/flowController";
import { authenticateToken } from "../middleware/authMiddleware";

const router = Router();
const flowController = new FlowController();

// 모든 플로우 라우트에 인증 미들웨어 적용
router.use(authenticateToken);

// ==================== 플로우 정의 ====================
router.post("/definitions", flowController.createFlowDefinition);
router.get("/definitions", flowController.getFlowDefinitions);
router.get("/definitions/:id", flowController.getFlowDefinitionDetail);
router.put("/definitions/:id", flowController.updateFlowDefinition);
router.delete("/definitions/:id", flowController.deleteFlowDefinition);

// ==================== 플로우 단계 ====================
router.get("/definitions/:flowId/steps", flowController.getFlowSteps); // 단계 목록 조회
router.post("/definitions/:flowId/steps", flowController.createFlowStep);
router.put("/steps/:stepId", flowController.updateFlowStep);
router.delete("/steps/:stepId", flowController.deleteFlowStep);

// ==================== 플로우 연결 ====================
router.get("/connections/:flowId", flowController.getFlowConnections); // 연결 목록 조회
router.post("/connections", flowController.createConnection);
router.delete("/connections/:connectionId", flowController.deleteConnection);

// ==================== 플로우 실행 ====================
router.get("/:flowId/step/:stepId/count", flowController.getStepDataCount);
router.get("/:flowId/step/:stepId/list", flowController.getStepDataList);
router.get(
  "/:flowId/step/:stepId/column-labels",
  flowController.getStepColumnLabels
);
router.get("/:flowId/steps/counts", flowController.getAllStepCounts);

// ==================== 데이터 이동 ====================
router.post("/move", flowController.moveData);
router.post("/move-batch", flowController.moveBatchData);

// ==================== 스텝 데이터 수정 (인라인 편집) ====================
router.put("/:flowId/step/:stepId/data/:recordId", flowController.updateStepData);

// ==================== 오딧 로그 ====================
router.get("/audit/:flowId/:recordId", flowController.getAuditLogs);
router.get("/audit/:flowId", flowController.getFlowAuditLogs);

// ==================== 프로시저/함수 ====================
router.get("/procedures", flowController.listProcedures);
router.get("/procedures/:name/parameters", flowController.getProcedureParameters);

export default router;
