import { NextResponse } from "next/server";
import { prisma } from "../../..//lib/db"; // ← was "@/src/lib/db"

export async function POST() {
  await prisma.plan.upsert({
    where: { code: "standard_monthly" },
    update: {},
    create: {
      code: "standard_monthly",
      name: "Standard Monthly",
      intervalUnit: "month",
      intervalCount: 1,
      priceCents: 999,
      currency: "USD",
    },
  });

  const book = await prisma.book.upsert({
    where: { slug: "sample-book" },
    update: {},
    create: {
      slug: "sample-book",
      title: "Sample Book",
      description: "Demo book",
      isPublished: true,
      publishedAt: new Date(),
    },
  });

  await prisma.chapter.upsert({
    where: { id: 1 },
    update: {},
    create: {
      bookId: book.id,
      chapterNumber: 1,
      title: "Chapter One",
      durationSec: 300,
      hlsKey: "books/sample-book/01/master.m3u8",
      isPreview: true,
    },
  });

  return NextResponse.json({ ok: true });
}
