// ============================================================
// 개발관리 E-BOM (M3 등록 / M4 조회) 라우트.
// app.ts: app.use("/api/development", devBomRoutes) — devPart 라우터와 prefix 공유.
// ============================================================

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

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

const excelUpload = multer({
  storage: multer.memoryStorage(),
  limits: { fileSize: 10 * 1024 * 1024 }, // 10MB
});

// M4 — 트리 (정/역전개) — /ebom-tree prefix (라우트 충돌 방지: /:objid 위)
router.get("/ebom-tree/ascending", ctrl.ascending);
router.get("/ebom-tree/descending", ctrl.descending);
router.get("/ebom-tree/ascending/excel", ctrl.excelAscending);
router.get("/ebom-tree/descending/excel", ctrl.excelDescending);
router.get("/ebom-tree/full", ctrl.treeFull);

// M3 Excel Import — /:objid 보다 위에 (라우트 충돌 방지)
router.post("/ebom/excel-parse", excelUpload.single("file"), ctrl.excelParse);
router.get("/ebom/excel-check-duplicate", ctrl.excelCheckDuplicate);
router.get("/ebom/excel-copy-source", ctrl.excelCopySource);
router.get("/ebom/excel-copy/:objid", ctrl.excelCopy);
router.post("/ebom/excel-save", ctrl.excelSave);

// M3 — 그리드 + CRUD
router.get("/ebom/list", ctrl.getList);
router.delete("/ebom", ctrl.removeMany);
router.put("/ebom/:objid/status", ctrl.updateStatus);
router.get("/ebom/:objid", ctrl.getByObjid);

export default router;
