import { NextResponse } from 'next/server';
import { withErrorHandler, RouteContext } from '@server/middleware/withErrorHandler';
import { withAuth, AuthedRequest } from '@server/middleware/withAuth';
import { ForbiddenError } from '@server/errors';
import { retryOutboxRow } from '@server/services/email/outbox.service';

export const POST = withErrorHandler(
  withAuth(async (req: AuthedRequest, ctx: RouteContext) => {
    if (req.session.role !== 'superadmin' && req.session.role !== 'support') throw new ForbiddenError();
    const { id } = await ctx.params;
    await retryOutboxRow(id);
    return NextResponse.json({ ok: true });
  })
);
