const express = require("express");
const router = express.Router();
const controller = require("../controllers/stores.controller");
const auth = require("../middleware/auth");
const {
  householdAccess,
  requireHouseholdAdmin,
  requireSystemAdmin,
} = require("../middleware/household");

// Public routes
router.get("/", auth, controller.getAllStores);

// Household store management
router.get(
  "/household/:householdId",
  auth,
  householdAccess,
  controller.getHouseholdStores
);
router.post(
  "/household/:householdId",
  auth,
  householdAccess,
  requireHouseholdAdmin,
  controller.addStoreToHousehold
);
router.delete(
  "/household/:householdId/:storeId",
  auth,
  householdAccess,
  requireHouseholdAdmin,
  controller.removeStoreFromHousehold
);
router.patch(
  "/household/:householdId/:storeId/default",
  auth,
  householdAccess,
  requireHouseholdAdmin,
  controller.setDefaultStore
);

// System admin routes
router.post("/", auth, requireSystemAdmin, controller.createStore);
router.patch("/:storeId", auth, requireSystemAdmin, controller.updateStore);
router.delete("/:storeId", auth, requireSystemAdmin, controller.deleteStore);

module.exports = router;
