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

const router = Router();

// 모든 레이아웃 라우트에 인증 미들웨어 적용
router.use(authenticateToken);

/**
 * @route   GET /api/layouts
 * @desc    레이아웃 목록 조회
 * @access  Private
 * @params  page, size, category, layoutType, searchTerm, includePublic
 */
router.get("/", layoutController.getLayouts.bind(layoutController));

/**
 * @route   GET /api/layouts/counts-by-category
 * @desc    카테고리별 레이아웃 개수 조회
 * @access  Private
 */
router.get(
  "/counts-by-category",
  layoutController.getLayoutCountsByCategory.bind(layoutController)
);

/**
 * @route   GET /api/layouts/:id
 * @desc    레이아웃 상세 조회
 * @access  Private
 * @params  id (layoutCode)
 */
router.get("/:id", layoutController.getLayoutById.bind(layoutController));

/**
 * @route   POST /api/layouts
 * @desc    레이아웃 생성
 * @access  Private
 * @body    CreateLayoutRequest
 */
router.post("/", layoutController.createLayout.bind(layoutController));

/**
 * @route   PUT /api/layouts/:id
 * @desc    레이아웃 수정
 * @access  Private
 * @params  id (layoutCode)
 * @body    Partial<CreateLayoutRequest>
 */
router.put("/:id", layoutController.updateLayout.bind(layoutController));

/**
 * @route   DELETE /api/layouts/:id
 * @desc    레이아웃 삭제
 * @access  Private
 * @params  id (layoutCode)
 */
router.delete("/:id", layoutController.deleteLayout.bind(layoutController));

/**
 * @route   POST /api/layouts/:id/duplicate
 * @desc    레이아웃 복제
 * @access  Private
 * @params  id (layoutCode)
 * @body    { newName: string }
 */
router.post(
  "/:id/duplicate",
  layoutController.duplicateLayout.bind(layoutController)
);

export default router;
