const router = require("express").Router();
const { authenticateAdmin, audit } = require("../../middleware");
const AdminAssetsController = require("../../controllers/admin/assetController");
const createUploader = require("../../middleware/createUploader");

// List + Read
router.get("/type/spot", authenticateAdmin, AdminAssetsController.getSpotAssets);
router.get("/", authenticateAdmin, AdminAssetsController.getAssets);
router.get("/:assetId", authenticateAdmin, AdminAssetsController.getAssetById);

// Create
router.post(
  "/",
  authenticateAdmin,
  createUploader({
    folder: 'assets',
    fieldName: 'logo',
    maxSizeMB: 20,
  }),
  audit("assets.create", "asset"),
  AdminAssetsController.createAsset
);

// Update
router.put(
  "/:assetId",
  authenticateAdmin,
  audit("assets.update", "asset"),
  AdminAssetsController.updateAsset
);

// Delete
router.delete(
  "/:assetId",
  authenticateAdmin,
  audit("assets.delete", "asset"),
  AdminAssetsController.deleteAsset
);

module.exports = router;