import { Router } from "express";
import {
  createAdminBanner,
  deleteAdminBanner,
  getAdminBannerById,
  listAdminBanners,
  updateAdminBanner,
} from "../controllers/bannerController.js";
import { requireStaff } from "../middleware/authMiddleware.js";
import {
  validateBody,
  validateParams,
  validateQuery,
} from "../middleware/validateRequest.js";
import { asyncHandler } from "../utils/asyncHandler.js";
import {
  bannerIdParamSchema,
  bannerListQuerySchema,
  createBannerSchema,
  updateBannerSchema,
} from "../validators/bannerValidators.js";

const router = Router();

router.use(requireStaff);

router.get(
  "/",
  validateQuery(bannerListQuerySchema),
  asyncHandler(listAdminBanners),
);

router.post(
  "/",
  validateBody(createBannerSchema),
  asyncHandler(createAdminBanner),
);

router.get(
  "/:id",
  validateParams(bannerIdParamSchema),
  asyncHandler(getAdminBannerById),
);

router.patch(
  "/:id",
  validateParams(bannerIdParamSchema),
  validateBody(updateBannerSchema),
  asyncHandler(updateAdminBanner),
);

router.delete(
  "/:id",
  validateParams(bannerIdParamSchema),
  asyncHandler(deleteAdminBanner),
);

export default router;
