DO $$
DECLARE
  jury_id TEXT;
  round_id TEXT;
  proj RECORD;
BEGIN
  SELECT id INTO jury_id FROM "User" WHERE email = 'jury.demo@monaco-opc.com';
  SELECT id INTO round_id FROM "Round" WHERE slug = 'mopc-2026-round-1';

  UPDATE "Round" SET status = 'ACTIVE', "votingStartAt" = NOW() - INTERVAL '7 days', "votingEndAt" = NOW() + INTERVAL '30 days' WHERE id = round_id;

  FOR proj IN SELECT id, title FROM "Project" WHERE "roundId" = round_id ORDER BY "createdAt" DESC LIMIT 8
  LOOP
    INSERT INTO "Assignment" (id, "userId", "projectId", "roundId", method, "isRequired", "isCompleted", "createdAt")
    VALUES ('demo-assign-' || substr(proj.id, 1, 15), jury_id, proj.id, round_id, 'MANUAL', true, false, NOW())
    ON CONFLICT ("userId", "projectId", "roundId") DO NOTHING;
    RAISE NOTICE 'Assigned: %', proj.title;
  END LOOP;

  RAISE NOTICE 'Done! Assigned projects to jury member.';
END $$;
