import { Application } from 'express';
import { Resource } from 'express-automatic-routes';
import { AuditLogService } from '#services/audit/auditLogService';
import { Req, Res } from '#interfaces/IApi';
import verify from '#middlewares/auth';
import { requireAdmin } from '#middlewares/auth';
import { auditAccessLogger } from '#middlewares/audit-access-logger';
import { sendSuccess } from '#utils/responseUtils';

export default (_express: Application) => {
	return <Resource>{
		get: {
			middleware: [verify, requireAdmin, auditAccessLogger('VIEWED')],
			handler: async (req: Req, res: Res) => {
				try {
					const { batch_id } = req.params;
					const logs = await AuditLogService.getByBatchId(batch_id as string);
					return sendSuccess(res, logs);
				} catch (error) {
					return res.error(error);
				}
			},
		},
	};
};
