"use strict";

const router = require("express").Router();
const { audit, authenticateAdmin } = require("../../middleware");

const AdminSignalsController = require("../../controllers/admin/signalsController");
const createUploader = require("../../middleware/createUploader");

// ✅ mount this in adminS.js as:
// router.use("/signals", AdminSignalsRoutes);
// (adminS.js already uses authenticateAdmin per route, but we keep it here for safety)

router.get("/providers", authenticateAdmin, AdminSignalsController.getProviders);
router.get("/providers/:providerId", authenticateAdmin, AdminSignalsController.getProviderById);

router.post(
  "/providers",
  authenticateAdmin,
  createUploader({
    folder: 'providers',
    fieldName: 'avatar',
    maxSizeMB: 20,
  }),
  audit("providers.create", "provider"),
  AdminSignalsController.createProvider
);

router.put(
  "/providers/:providerId",
  authenticateAdmin,
  createUploader({
    folder: 'providers',
    fieldName: 'avatar',
    maxSizeMB: 20,
  }),
  audit("providers.update", "provider"),
  AdminSignalsController.updateProvider
);

router.delete(
  "/providers/:providerId",
  authenticateAdmin,
  audit("providers.delete", "provider"),
  AdminSignalsController.deleteProvider
);

router.get("/", authenticateAdmin, AdminSignalsController.getSignals);
router.get("/:signalId", authenticateAdmin, AdminSignalsController.getSignalById);

router.post(
  "/",
  authenticateAdmin,
  audit("signals.create", "signal"),
  AdminSignalsController.createSignal
);

router.put(
  "/:signalId",
  authenticateAdmin,
  audit("signals.update", "signal"),
  AdminSignalsController.updateSignal
);

router.delete(
  "/:signalId",
  authenticateAdmin,
  audit("signals.delete", "signal"),
  AdminSignalsController.deleteSignal
);










module.exports = router;