import express from "express";
import multer from "multer";
import {
  createBlog,
  getAllBlogs,
  getBlogBySlug,
  likeBlog,
} from "../controllers/blog.controller.js";

import {
  createCategory,
  getCategories,
  deleteCategory,
} from "../controllers/category.controller.js";

import {
  addComment as addCommentController,
  getComments,
  deleteComment,
} from "../controllers/comment.controller.js";

const router = express.Router();
const upload = multer({ dest: "uploads/" });

// =======================
// Blog Routes
// =======================
// Create a blog
router.post("/", upload.single("image"), createBlog);

// Get all blogs
router.get("/", getAllBlogs);

// Get blog by slug
router.get("/:slug", getBlogBySlug);

// Like a blog
router.post("/:id/like", likeBlog);

// =======================
// Category Routes
// =======================
router.post("/category", createCategory); // Create Category (admin)
router.get("/category", getCategories); // List Categories
router.delete("/category/:id", deleteCategory); // Delete Category (admin)

// =======================
// Comment Routes
// =======================
router.post("/:blogId/comments", addCommentController); // Add Comment
router.get("/:blogId/comments", getComments); // Get Comments
router.delete("/:blogId/comments/:commentId", deleteComment); // Delete Comment (admin)

export default router;
