import express from 'express';
import { authenticateToken } from '../middleware/authMiddleware';
import { userMailController } from '../controllers/userMailController';

const router = express.Router();
router.use(authenticateToken);

router.post('/test-connection', (req, res) => userMailController.testConnectionDirect(req as any, res));
router.get('/accounts', (req, res) => userMailController.listAccounts(req as any, res));
router.post('/accounts', (req, res) => userMailController.createAccount(req as any, res));
router.put('/accounts/:accountId', (req, res) => userMailController.updateAccount(req as any, res));
router.delete('/accounts/:accountId', (req, res) => userMailController.deleteAccount(req as any, res));
router.post('/accounts/:accountId/test', (req, res) => userMailController.testConnection(req as any, res));
router.get('/accounts/:accountId/mails/stream', (req, res) => userMailController.streamMails(req as any, res));
router.get('/accounts/:accountId/mails', (req, res) => userMailController.listMails(req as any, res));
router.get('/accounts/:accountId/mails/:seqno', (req, res) => userMailController.getMailDetail(req as any, res));
router.post('/accounts/:accountId/mails/:seqno/mark-read', (req, res) => userMailController.markAsRead(req as any, res));
router.delete('/accounts/:accountId/mails/:seqno', (req, res) => userMailController.deleteMail(req as any, res));
router.get('/accounts/:accountId/folders', (req, res) => userMailController.listFolders(req as any, res));
router.get('/accounts/:accountId/folders/:folder/mails/stream', (req, res) => userMailController.streamFolderMails(req as any, res));
router.post('/accounts/:accountId/mails/:seqno/move', (req, res) => userMailController.moveMail(req as any, res));
router.get('/accounts/:accountId/mails/:seqno/attachments', (req, res) => userMailController.getAttachments(req as any, res));
router.get('/accounts/:accountId/mails/:seqno/attachment/:partId', (req, res) => userMailController.downloadAttachment(req as any, res));
router.post('/accounts/:accountId/send', (req, res) => userMailController.sendMail(req as any, res));

export default router;
