import { NextRequest, NextResponse } from 'next/server'; import { createDomainManager } from '@/lib/domainManagement'; export async function GET(request: NextRequest) { try { const universityId = request.headers.get('x-university-id'); if (!universityId) { return NextResponse.json( { error: 'University context required' }, { status: 400 } ); } const domainManager = createDomainManager(universityId); const domains = await domainManager.getDomains(); return NextResponse.json({ success: true, data: domains, }); } catch (error) { console.error('Error fetching domains:', error); return NextResponse.json( { error: 'Failed to fetch domains' }, { status: 500 } ); } } export async function POST(request: NextRequest) { try { const universityId = request.headers.get('x-university-id'); if (!universityId) { return NextResponse.json( { error: 'University context required' }, { status: 400 } ); } const body = await request.json(); const { type, domain, subdomain } = body; if (!type || !domain) { return NextResponse.json( { error: 'Type and domain are required' }, { status: 400 } ); } const domainManager = createDomainManager(universityId); const newDomain = await domainManager.addDomain(type, domain, subdomain); return NextResponse.json({ success: true, data: newDomain, message: 'Domain configuration created successfully', }); } catch (error) { console.error('Error creating domain:', error); return NextResponse.json( { error: error instanceof Error ? error.message : 'Failed to create domain' }, { status: 500 } ); } }