/**
 * 공정 작업기준 라우트
 */

import express from "express";
import { authenticateToken } from "../middleware/authMiddleware";
import * as ctrl from "../controllers/processWorkStandardController";

const router = express.Router();

router.use(authenticateToken);

// 품목/라우팅/공정 조회 (좌측 트리)
router.get("/items", ctrl.getItemsWithRouting);
router.get("/items/:itemCode/routings", ctrl.getRoutingsWithProcesses);

// 기본 버전 설정/해제
router.put("/versions/:versionId/set-default", ctrl.setDefaultVersion);
router.put("/versions/:versionId/unset-default", ctrl.unsetDefaultVersion);

// 작업 항목 CRUD
router.get("/routing-detail/:routingDetailId/work-items", ctrl.getWorkItems);
router.post("/work-items", ctrl.createWorkItem);
router.put("/work-items/:id", ctrl.updateWorkItem);
router.delete("/work-items/:id", ctrl.deleteWorkItem);

// 작업 항목 상세 CRUD
router.get("/work-items/:workItemId/details", ctrl.getWorkItemDetails);
router.post("/work-item-details", ctrl.createWorkItemDetail);
router.put("/work-item-details/:id", ctrl.updateWorkItemDetail);
router.delete("/work-item-details/:id", ctrl.deleteWorkItemDetail);

// 전체 저장 (일괄)
router.put("/save-all", ctrl.saveAll);

// 등록 품목 관리 (화면별 품목 목록)
router.get("/registered-items/:screenCode", ctrl.getRegisteredItems);
router.post("/registered-items", ctrl.registerItem);
router.post("/registered-items/batch", ctrl.registerItemsBatch);
router.delete("/registered-items/:id", ctrl.unregisterItem);

export default router;
