import { Router } from 'express';
import { LegalController } from '../controllers/legal.controller';
import { authenticate, requireRole } from '../middleware/auth.middleware';
import { upload } from '../middleware/upload.middleware';

const router = Router();
const legalController = new LegalController();

router.use(authenticate);

// Admins create documents
router.post('/documents', requireRole('ADMIN'), legalController.create);
router.get('/documents', requireRole('ADMIN'), legalController.listAll);

// Anyone can view active docs and sign them
router.get('/documents/active/:type', legalController.getActive);
router.post('/accept', legalController.accept);
router.post('/sign', legalController.sign);
router.post('/upload', upload.single('file'), legalController.uploadSignedDoc);
router.get('/my-acceptances', legalController.myAcceptances);

// Admin Approval Routes
router.get('/pending', requireRole('ADMIN'), legalController.getPending);
router.post('/approve/:partnerId', requireRole('ADMIN'), legalController.approvePartner);

export default router;
