const router = require('express').Router();
const ctrl = require('../controllers/customer.controller');
const { authenticate } = require('../middlewares/auth');
const { validate } = require('../middlewares/validate');
const { customerSchemas, paramsSchemas } = require('../validators');

router.use(authenticate);

router.get('/', ctrl.getAll);
router.get('/payments-all', ctrl.getAllPayments);
router.get('/:id', ctrl.getById);
router.post('/', validate({ body: customerSchemas.create }), ctrl.create);
router.put('/:id', validate({ params: paramsSchemas.idParam, body: customerSchemas.update }), ctrl.update);
router.delete('/:id', validate({ params: paramsSchemas.idParam }), ctrl.remove);

// Sub-resources
router.get('/:id/ledger', ctrl.getLedger);
router.get('/:id/payments', ctrl.getPayments);
router.post(
	'/:id/payments',
	validate({ params: paramsSchemas.idParam, body: customerSchemas.addPayment }),
	ctrl.addPayment
);
router.post(
	'/:id/dues',
	validate({ params: paramsSchemas.idParam, body: customerSchemas.addDue }),
	ctrl.addDue
);

module.exports = router;
