import express from "express";
import { authenticateToken } from "../middleware/authMiddleware";
import {
  getDesignRequestList, getDesignRequestDetail, createDesignRequest, updateDesignRequest, deleteDesignRequest, addRequestHistory,
  getProjectList, getProjectDetail, createProject, updateProject, deleteProject,
  getTasksByProject, createTask, updateTask, deleteTask,
  getWorkLogsByTask, createWorkLog, deleteWorkLog,
  createSubItem, updateSubItem, deleteSubItem,
  createIssue, updateIssue,
  getEcnList, createEcn, updateEcn, deleteEcn,
  getMyWork,
  createPurchaseReq, createCoopReq, addCoopResponse,
} from "../controllers/designController";

const router = express.Router();
router.use(authenticateToken);

// 설계의뢰/설변요청 (DR/ECR)
router.get("/requests", getDesignRequestList);
router.get("/requests/:id", getDesignRequestDetail);
router.post("/requests", createDesignRequest);
router.put("/requests/:id", updateDesignRequest);
router.delete("/requests/:id", deleteDesignRequest);
router.post("/requests/:id/history", addRequestHistory);

// 설계 프로젝트
router.get("/projects", getProjectList);
router.get("/projects/:id", getProjectDetail);
router.post("/projects", createProject);
router.put("/projects/:id", updateProject);
router.delete("/projects/:id", deleteProject);

// 프로젝트 태스크
router.get("/projects/:projectId/tasks", getTasksByProject);
router.post("/projects/:projectId/tasks", createTask);
router.put("/tasks/:taskId", updateTask);
router.delete("/tasks/:taskId", deleteTask);

// 작업일지
router.get("/tasks/:taskId/work-logs", getWorkLogsByTask);
router.post("/tasks/:taskId/work-logs", createWorkLog);
router.delete("/work-logs/:workLogId", deleteWorkLog);

// 태스크 하위항목
router.post("/tasks/:taskId/sub-items", createSubItem);
router.put("/sub-items/:subItemId", updateSubItem);
router.delete("/sub-items/:subItemId", deleteSubItem);

// 태스크 이슈
router.post("/tasks/:taskId/issues", createIssue);
router.put("/issues/:issueId", updateIssue);

// ECN (설변통보)
router.get("/ecn", getEcnList);
router.post("/ecn", createEcn);
router.put("/ecn/:id", updateEcn);
router.delete("/ecn/:id", deleteEcn);

// 나의 업무
router.get("/my-work", getMyWork);

// 구매요청 / 협업요청
router.post("/work-logs/:workLogId/purchase-reqs", createPurchaseReq);
router.post("/work-logs/:workLogId/coop-reqs", createCoopReq);
router.post("/coop-reqs/:coopReqId/responses", addCoopResponse);

export default router;
