import { selectTemplate } from "../../../../utils/inquirer.js";
import { setGraphAILogger } from "../../../../cli/helpers.js";
import { storyToScript } from "../../../../tools/story_to_script.js";
import { mulmoStoryboardSchema } from "../../../../types/schema.js";
import { getBaseDirPath, getFullPath, readAndParseJson } from "../../../../utils/file.js";
import { outDirName } from "../../../../types/const.js";
export const handler = async (argv) => {
    const { v: verbose, s: filename, file, o: outdir, b: basedir, beats_per_scene, llm, llm_model, mode } = argv;
    let { t: template } = argv;
    const baseDirPath = getBaseDirPath(basedir);
    const outDirPath = getFullPath(baseDirPath, outdir ?? outDirName);
    if (!template) {
        template = await selectTemplate();
    }
    setGraphAILogger(verbose, {
        outdir: outDirPath,
        basedir: baseDirPath,
        template,
        fileName: filename,
        beatsPerScene: beats_per_scene,
        storyFilePath: file,
        llmAgent: llm,
        llmModel: llm_model,
    });
    const parsedStory = readAndParseJson(file, mulmoStoryboardSchema);
    await storyToScript({
        story: parsedStory,
        beatsPerScene: beats_per_scene,
        templateName: template,
        outdir: outDirPath,
        fileName: filename,
        llm,
        llmModel: llm_model,
        generateMode: mode,
    });
};
