const express = require('express')
const router = express.Router();
const { authenticate, requireKyc } = require('../middleware')
const { fundingController } = require('../controllers');
const { validate, rules, body } = require('../middleware/validation');
const uploadDepositProof = require('../middleware/uploadDepositProof')


router.get('/deposit', authenticate, fundingController.getDeposit)
router.get('/deposit/pay/:id', authenticate, fundingController.payDeposit)
router.post('/deposit/upload/:id', authenticate, (req, res, next) => {
    uploadDepositProof(req, res, function (err) {
        if (err) return next(err);
        next();
    });
},
    fundingController.uploadDeposit)
router.post('/deposit/cancel/:id' ,  authenticate ,fundingController.cancelDeposit)
router.get('/withdrawal', authenticate, fundingController.getWithdrawal)
router.get('/withdrawal', authenticate, fundingController.getHistory)
router.get('/make', authenticate, fundingController.makeWithdrawal)
router.post(
    '/deposit',
    authenticate,
    [
        rules.amount,
        body('method').optional().trim(),
    ],
    validate,
    fundingController.startDeposit
)
router.post(
    '/withdraw',
    authenticate,
    requireKyc('level1'),
    [
        rules.amount,
        body('otp').trim(),
        body('type').isIn(['external', 'wallet']),
        body('details').trim(),
        body('method').optional().trim(),
        body('symbol').optional().trim(),
        body('network').optional().trim(),
    ],
    validate,
    fundingController.requestWithdrawal
)

router.get('/history', authenticate, fundingController.getHistory)

module.exports = router