import { Router } from 'express';
import { AfterSalesController } from '../controllers/AfterSalesController';
import { requireTraceContext } from '../../core/guards/trace-context.guard';
import { requirePermission } from '../../core/guards/rbac.guard';

const router = Router();

router.post('/init-tables', requireTraceContext, requirePermission('admin'), AfterSalesController.initTables);

router.post('/', requireTraceContext, requirePermission('after_sales:write'), AfterSalesController.createRequest);

router.get('/', requireTraceContext, requirePermission('after_sales:read'), AfterSalesController.getRequests);

router.get('/:id', requireTraceContext, requirePermission('after_sales:read'), AfterSalesController.getRequestById);

router.post('/:id/approve', requireTraceContext, requirePermission('after_sales:write'), AfterSalesController.approveRequest);

router.post('/:id/close', requireTraceContext, requirePermission('after_sales:write'), AfterSalesController.closeRequest);

router.post('/refunds/:refundId/process', requireTraceContext, requirePermission('after_sales:write'), AfterSalesController.processRefund);

router.get('/refunds/:refundId', requireTraceContext, requirePermission('after_sales:read'), AfterSalesController.getRefundById);

router.post('/returns/:returnId/process', requireTraceContext, requirePermission('after_sales:write'), AfterSalesController.processReturn);

router.get('/returns/:returnId', requireTraceContext, requirePermission('after_sales:read'), AfterSalesController.getReturnById);

export default router;
