import Foundation
import PackagePlugin

@main struct Plugin: CommandPlugin {
    func performCommand(context: PluginContext, arguments _: [String]) async throws {
        let createAPI = try context.tool(named: "create-api")
        // let workingDirectory = context.package.directory.appending("openapi")

        let process = Process()
        process.currentDirectoryURL = URL(fileURLWithPath: context.package.directory.string)
        process.executableURL = URL(fileURLWithPath: createAPI.path.string)
        process.arguments = [
            "generate",
            "schema.json",
            "--config", "config.yml",
            "--output", "Generated",
        ]

        try process.run()
        process.waitUntilExit()
    }
}
