/**
 * Seeds the five media categories (PLANNING.md §6c, Q5 — data, not an enum).
 * Slugs + labels match the frontend's gallery captions
 * (genesiscoworkingspace-landing-page/src/content/snapshots/gallery.*.json).
 *
 * Idempotent: `.onConflict('slug').merge()` compiles to ON DUPLICATE KEY UPDATE,
 * so re-running updates labels/positions in place and never duplicates a row.
 */
import type { Knex } from 'knex';

const CATEGORIES: ReadonlyArray<{ slug: string; label: string; position: number }> = [
  { slug: 'office', label: 'Office', position: 1 },
  { slug: 'function-hall', label: 'Function Hall', position: 2 },
  { slug: 'sharing-corner', label: 'Sharing Corner', position: 3 },
  { slug: 'event-space', label: 'Event Space', position: 4 },
  { slug: 'meeting-room', label: 'Meeting Room', position: 5 },
];

export async function seed(knex: Knex): Promise<void> {
  for (const row of CATEGORIES) {
    await knex('media_categories').insert(row).onConflict('slug').merge(['label', 'position']);
  }
  console.log(`[seed] media_categories: ${CATEGORIES.length} rows upserted`);
}
