import type { Kysely } from "kysely";

// Adds a "dashboard" feature so the dashboard page can be access-controlled like
// every other module. Super admins keep full access; other roles see the
// dashboard only once granted dashboard:read. Existing roles are NOT auto-granted
// (the dashboard becomes opt-in per role).
const FEATURES = [{ name: "Dashboard", slug: "dashboard" }];

export async function up(db: Kysely<any>): Promise<void> {
  await db
    .insertInto("console_features")
    .values(FEATURES.map((f) => ({ name: f.name, slug: f.slug, is_active: true })))
    .onConflict((oc) => oc.column("slug").doNothing())
    .execute();
}

export async function down(db: Kysely<any>): Promise<void> {
  await db
    .deleteFrom("console_features")
    .where(
      "slug",
      "in",
      FEATURES.map((f) => f.slug),
    )
    .execute();
}
