import { GoogleGenAI } from "@google/genai";

const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });

const prompt =
  "A cinematic shot of a cat astronaut walking on the moon. Include subtle wind ambience.";

let operation = await ai.models.generateVideos({
  model: "veo-3.1-generate-preview",
  prompt,
  config: { resolution: "1080p" },
});

while (!operation.done) {
  await new Promise((resolve) => setTimeout(resolve, 10_000));
  operation = await ai.operations.getVideosOperation({ operation });
  console.log("Polling...");
}

const video = operation.response?.generatedVideos?.[0]?.video;
if (!video) {
  throw new Error("No video returned");
}

await ai.files.download({ file: video, downloadPath: "out.mp4" });
console.log("Saved out.mp4");
