const admin = require("firebase-admin");
const serviceAccount = require("./serviceAccountKey.json");
const { googleAI, gemini25FlashLite } = require("@genkit-ai/googleai");
const { GEMINI_API_KEY } = require("./config/keys");
const { genkit } = require("genkit");

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  storageBucket: "musicland-d33f9.firebasestorage.app",
});

exports.generateAI = async ({ system = "", prompt = "", schema }) => {
  const genkitInstance = genkit({
    plugins: [
      googleAI({
        apiKey: GEMINI_API_KEY,
      }),
    ],
    model: gemini25FlashLite,
  });

  if (prompt?.length < 1) {
    throw new Error(
      "Vous devez spécifier un prompt pour effectuer cette action.",
    );
  }

  const { output } = await genkitInstance.generate({
    system,
    prompt,
    output: { schema },
  });

  return output;
};

// Exporter toutes les fonctions
exports.music = require("./src/music");
exports.lyrics = require("./src/lyrics");
