import express from "express";
import {
  ApprovalDefinitionController,
  ApprovalTemplateController,
  ApprovalRequestController,
  ApprovalLineController,
} from "../controllers/approvalController";
import { ApprovalProxyController } from "../controllers/approvalProxyController";
import { authenticateToken } from "../middleware/authMiddleware";

const router = express.Router();

router.use(authenticateToken);

// ==================== 결재 유형 (Definitions) ====================
router.get("/definitions", ApprovalDefinitionController.getDefinitions);
router.get("/definitions/:id", ApprovalDefinitionController.getDefinition);
router.post("/definitions", ApprovalDefinitionController.createDefinition);
router.put("/definitions/:id", ApprovalDefinitionController.updateDefinition);
router.delete("/definitions/:id", ApprovalDefinitionController.deleteDefinition);

// ==================== 결재선 템플릿 (Templates) ====================
router.get("/templates", ApprovalTemplateController.getTemplates);
router.get("/templates/:id", ApprovalTemplateController.getTemplate);
router.post("/templates", ApprovalTemplateController.createTemplate);
router.put("/templates/:id", ApprovalTemplateController.updateTemplate);
router.delete("/templates/:id", ApprovalTemplateController.deleteTemplate);

// ==================== 결재 요청 (Requests) ====================
router.get("/requests", ApprovalRequestController.getRequests);
router.get("/requests/:id", ApprovalRequestController.getRequest);
router.post("/requests", ApprovalRequestController.createRequest);
router.post("/requests/:id/cancel", ApprovalRequestController.cancelRequest);
router.post("/requests/:id/post-approve", ApprovalRequestController.postApprove);

// ==================== 결재 라인 처리 (Lines) ====================
router.get("/my-pending", ApprovalLineController.getMyPendingLines);
router.post("/lines/:lineId/process", ApprovalLineController.processApproval);

// ==================== 대결 위임 설정 (Proxy Settings) ====================
router.get("/proxy-settings", ApprovalProxyController.getProxySettings);
router.post("/proxy-settings", ApprovalProxyController.createProxySetting);
router.put("/proxy-settings/:id", ApprovalProxyController.updateProxySetting);
router.delete("/proxy-settings/:id", ApprovalProxyController.deleteProxySetting);
router.get("/proxy-settings/check/:userId", ApprovalProxyController.checkActiveProxy);

export default router;
