import { Router } from "express";
import {
    getStations,
    getStationById,
    createStation,
    updateStation,
    deleteStation,
    getStationQueue,
    getProductionQueue,
    getStationProductionWorkflow,
    getStationStats,
    getProductionStationStats,
    setStationProducts,
    getStationProductDepositLinks,
    replaceStationProductDepositLinks,
    setStationShopUsers,
    getStationStock,
    getStationProducts,
    getRunnerQueue,
    getHasRunner,
    updateStationProductionWorkflow,
    postSendToReserve,
    postUseFromStock,
    postIncrementStock,
    postDecrementStock
} from "./station.controller";

import { protect } from "../../middlewares/auth.middleware";
import { attachShop } from "../../middlewares/shop.middleware";

const router = Router({ mergeParams: true });

router.use(protect);
router.use(attachShop);

router.get("/", getStations);
router.get("/runner-queue", getRunnerQueue);
router.get("/:id", getStationById);
router.post("/", createStation);
router.patch("/:id", updateStation);
router.put("/:id/shop-users", setStationShopUsers);
router.put("/:id/products", setStationProducts);
router.get("/:id/products/:productId/deposit-links", getStationProductDepositLinks);
router.put("/:id/products/:productId/deposit-links", replaceStationProductDepositLinks);
router.delete("/:id", deleteStation);
router.get("/:id/queue", getStationQueue);
router.get("/:id/production-queue", getProductionQueue);
router.get("/:id/production-stats", getProductionStationStats);
router.get("/:id/production-workflow", getStationProductionWorkflow);
router.put("/:id/production-workflow", updateStationProductionWorkflow);
router.get("/:id/products", getStationProducts);
router.get("/:id/has-runner", getHasRunner);
router.get("/:id/stats", getStationStats);

// Stock management
router.get("/:id/stock", getStationStock);
router.post("/:id/stock/send-to-reserve", postSendToReserve);
router.post("/:id/stock/use", postUseFromStock);
router.post("/:id/stock/increment", postIncrementStock);
router.post("/:id/stock/decrement", postDecrementStock);

export default router;