import { NextRequest, NextResponse } from 'next/server';
import { getContact, getMessages } from '@/lib/db';

export async function GET(
  _req: NextRequest,
  { params }: { params: { contactId: string } }
) {
  try {
    const { contactId } = params;

    const contact = getContact(contactId);
    if (!contact) {
      return NextResponse.json({ error: 'Contact not found' }, { status: 404 });
    }

    const messages = getMessages(contactId, 200);

    return NextResponse.json({ contact, messages });
  } catch (err) {
    console.error('GET /api/conversations/[contactId] error:', err);
    return NextResponse.json({ error: 'Failed to load conversation' }, { status: 500 });
  }
}
