const express = require('express');
const router = express.Router();
const { requireAuth } = require('../middleware/auth');
const { createRequirePage } = require('../../../shared/middleware/pagePermission');
const { getPool } = require('../../shared/config/database');
const requirePage = createRequirePage(getPool);
const ctrl = require('../controllers/partnerController');
const partnerPerm = requirePage('tkuser.partners');

router.use(requireAuth);

router.get('/', ctrl.list);
router.get('/:id/delete-info', requirePage('tkuser.partners'), ctrl.getDeleteInfo);
router.delete('/:id/permanent', requirePage('tkuser.partners'), ctrl.permanentDelete);
router.get('/:id', ctrl.getById);
router.post('/', partnerPerm, ctrl.create);
router.put('/:id', partnerPerm, ctrl.update);
router.delete('/:id', partnerPerm, ctrl.deactivate);

router.get('/:id/workers', ctrl.listWorkers);
router.post('/:id/workers', partnerPerm, ctrl.createWorker);
router.put('/workers/:id', partnerPerm, ctrl.updateWorker);
router.delete('/workers/:id', partnerPerm, ctrl.deactivateWorker);

module.exports = router;
