import { mutation } from "./_generated/server";

/**
 * Run this in the Convex dashboard to seed demo games
 */
export const seedDemoGames = mutation({
  handler: async (ctx) => {
    // Create system creator if it doesn't exist
    const [creator] = await ctx.db
      .query("creators")
      .withIndex("by_handle", (q) => q.eq("handle", "@system"))
      .collect();

    const creatorId =
      creator?._id ??
      (await ctx.db.insert("creators", {
        handle: "@system",
        displayName: "System",
        bio: "Demo games and examples",
      }));

    // Seed demo game
    const demoGame = await ctx.db.insert("games", {
      title: "Beat Clicker",
      slug: "demo-game",
      srcUrl: "/games/demo-game/index.html",
      runtime: "vercel-static",
      coverUrl: "https://images.unsplash.com/photo-1511379938547-c1f69419868d?w=400&h=400&fit=crop",
      description: "A simple rhythm-based clicker game. Click to the beat and score points!",
      tags: ["rhythm", "clicker", "beginner-friendly"],
      creatorId,
      visibility: "public",
      publishedAt: Date.now(),
      plays: 0,
      likes: 0,
    });

    return { success: true, gameId: demoGame };
  },
});
