import express from "express";
import {
  getAllCars,
  getCar,
  createCar,
  updateCar,
  deleteCar
} from "../controllers/carController.js";
import { verifyToken } from "../middleware/authMiddleware.js";
import { adminOnly } from "../middleware/roleMiddleware.js";

const router = express.Router();

// GET /cars - any authenticated user
router.get("/", verifyToken, getAllCars);

// GET /cars/:id - any authenticated user
router.get("/:id", verifyToken, getCar);

// POST /cars - admin only
router.post("/", verifyToken, adminOnly, createCar);

// PUT /cars/:id - admin only
router.put("/:id", verifyToken, adminOnly, updateCar);

// DELETE /cars/:id - admin only
router.delete("/:id", verifyToken, adminOnly, deleteCar);

export default router;