const express = require('express');
const router = express.Router();
const botController = require('../controllers/botController');
const { authenticate } = require('../middleware/auth');

// Marketplace routes
// Marketplace (templates)
router.get("/marketplace", authenticate, botController.getMarketplaceBots);
router.get("/marketplace/:marketplaceBotId", authenticate, botController.getMarketplaceBotDetails);

// Create an instance from a marketplace bot (deploy)
router.post("/marketplace/:marketplaceBotId/deploy", authenticate, botController.deployBot);

// Reviews / ratings (recommended: reviews belong to the marketplace bot, but come from an instance)
router.post("/marketplace/:marketplaceBotId/review", authenticate, botController.reviewMarketplaceBot);

// User instances
router.get("/instances", authenticate, botController.getMyBotInstances);
router.get("/instances/:instanceId", authenticate, botController.getBotInstanceDetails);

// Lifecycle controls (instance-based)
router.post("/instances/:instanceId/start", authenticate, botController.startBotInstance);
router.post("/instances/:instanceId/stop", authenticate, botController.stopBotInstance);
router.post("/instances/:instanceId/pause", authenticate, botController.pauseBotInstance);
router.post("/instances/:instanceId/resume", authenticate, botController.resumeBotInstance);

// Config updates (instance)
router.put("/instances/:instanceId/config", authenticate, botController.updateBotInstanceConfig);

// Billing / entitlement (if you keep billing fields on BotInstance)
router.post("/instances/:instanceId/billing/cancel", authenticate, botController.cancelAutoRenew);
router.post("/instances/:instanceId/billing/renew", authenticate, botController.renewSubscription);
router.post("/instances/:instanceId/billing/change-plan", authenticate, botController.changePlan);

// Stats & logs (instance-based)
router.get("/instances/:instanceId/stats", authenticate, botController.getBotInstanceStats);
router.get("/instances/:instanceId/orders", authenticate, botController.getBotInstanceOrders);
router.get("/instances/:instanceId/events", authenticate, botController.getBotInstanceEvents);

// Delete instance
router.delete("/instances/:instanceId", authenticate, botController.deleteBotInstance);


module.exports = router;