import { join } from "node:path";
import { mergeAppExtensions } from "./merge-app-extensions.js";
import { writeGeneratedFile } from "./write-generated-file.js";
export async function generateAppExtensionsDts(rootDir, entries, options = {}) {
    const filePath = join(rootDir, "src", "types", "generated", "app-extensions.generated.d.ts");
    const merged = mergeAppExtensions(entries);
    const lines = [
        "// Auto-generated by vext typegen (experimental). DO NOT EDIT.",
        "",
        'import "vextjs";',
        "",
        'declare module "vextjs" {',
        "  interface VextApp {",
        ...merged.entries.map((entry) => `    ${entry.propertyKey}: ${entry.inferredTypeText};`),
        "  }",
        "}",
        "",
    ];
    return {
        file: await writeGeneratedFile(filePath, lines.join("\n"), options),
        warnings: merged.warnings,
    };
}
