import { NextRequest, NextResponse } from 'next/server' import { verifyAdminAuth } from '@/lib/admin-auth' import { mailgunService } from '@/lib/mailgun' export const runtime = 'nodejs' export async function POST(request: NextRequest) { try { const adminUser = await verifyAdminAuth(request) if (!adminUser) { return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) } const body = await request.json() const { testType, email } = body if (testType === 'connection') { // Test connection to Mailgun const result = await mailgunService.testConnection() return NextResponse.json(result) } if (testType === 'email') { // Send test email if (!email) { return NextResponse.json({ success: false, error: 'Email address is required for email test' }, { status: 400 }) } const result = await mailgunService.sendEmail({ to: email, subject: 'Biblical Guide - Email Configuration Test', text: `Hello, This is a configuration test email from Biblical Guide. Your email system has been successfully configured and is working properly. You can now receive important notifications from our platform. Best regards, The Biblical Guide Team --- This is an automated message. Please do not reply to this email. Time: ${new Date().toLocaleString()}`, html: ` Biblical Guide - Email Configuration Test

Biblical Guide

Email Configuration Test

Hello,

This is a configuration test email from Biblical Guide.

Your email system has been successfully configured and is working properly. You can now receive important notifications from our platform.

✓ Configuration successful

Best regards,
The Biblical Guide Team

This is an automated message. Please do not reply to this email.

Time: ${new Date().toLocaleString()}

` }) return NextResponse.json(result) } return NextResponse.json({ success: false, error: 'Invalid test type' }, { status: 400 }) } catch (error) { console.error('Error testing Mailgun:', error) return NextResponse.json({ success: false, error: error instanceof Error ? error.message : 'Test failed' }, { status: 500 }) } }