// scripts/seed-seranking-unlimited.ts
// One-off flag flip: marks the eleva-seo org as SE-Ranking unlimited
// (bypasses all sync decrement — see organization.serankingUnlimited,
// migration 0063). Org id is hardcoded per the product decision (spec
// 2026-07-14-seranking-monetization-design.md § Décisions produit #4) — same
// seed to be replayed in prod via the ops runbook. Idempotent (plain UPDATE).
//
//   bun --env-file=.env.local run scripts/seed-seranking-unlimited.ts
//
// Guarded by assertSeedableDb() — refuses to run outside seo_insight_dev/test*.
import { eq } from "drizzle-orm";
import { assertSeedableDb } from "@/lib/db/assert-test-db";
import { organization } from "@/lib/db/auth-schema";
import { client, db } from "@/lib/db/client";

const ORG_ID = "0668c152-17e1-4cee-8fca-f3f0a91136df"; // eleva-seo

async function main() {
  // Hard guard: refuses a leaked/prod DATABASE_URL (accepts dev + test only).
  await assertSeedableDb();

  const rows = await db
    .update(organization)
    .set({ serankingUnlimited: true })
    .where(eq(organization.id, ORG_ID))
    .returning({ id: organization.id });

  console.log(`✓ seranking_unlimited=true: ${rows.length} ligne(s) touchée(s)`);
  if (rows.length !== 1) {
    throw new Error(
      `Attendu exactement 1 ligne touchée (org ${ORG_ID}), obtenu ${rows.length}`,
    );
  }

  await client.end();
}

await main();
