const express = require('express');
const {authenticate, requirePermission} = require('../middleware/auth');
const dashboardService = require('../services/dashboardService');
const {asyncHandler} = require('../utils/asyncHandler');
const {success} = require('../utils/apiResponse');

const router = express.Router();

router.use(authenticate, requirePermission('dashboard.view'));

router.get('/summary', asyncHandler(async (req, res) => {
  const data = await dashboardService.getSummary(req.user.shop_id, req.query);
  return success(res, data);
}));

router.get('/recent-loans', asyncHandler(async (req, res) => {
  const data = await dashboardService.recentLoans(req.user.shop_id);
  return success(res, data);
}));

router.get('/recent-customers', asyncHandler(async (req, res) => {
  const data = await dashboardService.recentCustomers(req.user.shop_id);
  return success(res, data);
}));

module.exports = router;
