/**
 * Seed default billing plans
 * ----------------------------
 * Run with: npx ts-node prisma/seed-plans.ts
 * Or via the API: POST /api/billing { action: "seed_plans" }
 *
 * Creates 4 plans: Free, Starter ($49/mo), Pro ($149/mo), Enterprise ($499/mo)
 */

import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

async function main() {
  const plans = [
    {
      name: "Free",
      slug: "free",
      priceMonthly: 0,
      sortOrder: 0,
      limitBrands: 1,
      limitWebsites: 1,
      limitEvents: 1000,
      limitUsers: 1,
      features: {
        dashboard: true,
        technical_audit: true,
        site_tag: true,
      },
    },
    {
      name: "Starter",
      slug: "starter",
      priceMonthly: 4900,    // $49.00
      sortOrder: 1,
      limitBrands: 3,
      limitWebsites: 3,
      limitEvents: 10000,
      limitUsers: 3,
      features: {
        dashboard: true,
        technical_audit: true,
        site_tag: true,
        content_briefs: true,
        competitors: true,
        ai_avatar: true,
      },
    },
    {
      name: "Pro",
      slug: "pro",
      priceMonthly: 14900,   // $149.00
      sortOrder: 2,
      limitBrands: 10,
      limitWebsites: 10,
      limitEvents: 100000,
      limitUsers: 10,
      features: {
        dashboard: true,
        technical_audit: true,
        site_tag: true,
        content_briefs: true,
        competitors: true,
        ai_avatar: true,
        conversion_intelligence: true,
        local_geo: true,
        report_studio: true,
      },
    },
    {
      name: "Enterprise",
      slug: "enterprise",
      priceMonthly: 49900,   // $499.00
      sortOrder: 3,
      limitBrands: 100,
      limitWebsites: 100,
      limitEvents: 1000000,
      limitUsers: 50,
      features: {
        dashboard: true,
        technical_audit: true,
        site_tag: true,
        content_briefs: true,
        competitors: true,
        ai_avatar: true,
        conversion_intelligence: true,
        local_geo: true,
        report_studio: true,
        api_access: true,
        white_label: true,
      },
    },
  ];

  for (const p of plans) {
    await prisma.plan.upsert({
      where: { slug: p.slug },
      create: { ...p, features: p.features },
      update: { ...p, features: p.features },
    });
    console.log(`  ✓ ${p.name} plan — $${(p.priceMonthly / 100).toFixed(2)}/mo, ${p.limitBrands} brands, ${p.limitEvents.toLocaleString()} events`);
  }

  console.log("\nDone! 4 plans seeded.");
}

main()
  .catch(console.error)
  .finally(() => prisma.$disconnect());
