import { NextResponse } from 'next/server';
import { readData, writeData, validateAuth } from '@/lib/cms';
import { testimonials } from '@/lib/data/testimonials';

export async function GET() {
  return NextResponse.json(readData('testimonials', testimonials));
}

export async function POST(request: Request) {
  if (!validateAuth(request)) {
    return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
  }

  try {
    const data = await request.json();
    writeData('testimonials', data);
    return NextResponse.json({ ok: true });
  } catch {
    return NextResponse.json({ error: 'Invalid data' }, { status: 400 });
  }
}
