import { Router } from 'express';
import { query } from 'express-validator';
import { listReturns } from '../controllers/returnController.js';
import { protect } from '../middlewares/auth.js';
import { handleValidation } from '../utils/handleValidation.js';

const router = Router();

router.get(
  '/',
  protect,
  query('page').optional().isInt({ min: 1 }),
  query('limit').optional().isInt({ min: 1, max: 100 }),
  query('billNumber').optional().isString().trim(),
  query('returnNumber').optional().isString().trim(),
  query('customer').optional().isString().trim(),
  query('product').optional().isString().trim(),
  query('barcode').optional().isString().trim(),
  query('reason').optional().isIn(['CUSTOMER_RETURN', 'DAMAGED_PRODUCT', 'WRONG_PRODUCT', 'DEFECTIVE_PRODUCT', 'EXPIRED_PRODUCT', 'OTHER']),
  query('refundMethod').optional().isIn(['CASH', 'UPI', 'CARD', 'STORE_CREDIT']),
  query('from').optional().isISO8601(),
  query('to').optional().isISO8601(),
  handleValidation,
  listReturns
);

export default router;
