import { NextResponse } from 'next/server';
import dbConnect from '../../../../src/lib/mongodb';
import State from '../../../../src/models/State';

export async function GET() {
  try {
    await dbConnect();
    const states = await State.find({});
    return NextResponse.json({ success: true, data: states });
  } catch (error: any) {
    console.error('Error fetching states:', error);
    return NextResponse.json({ success: false, error: error.message }, { status: 500 });
  }
}
