/**
 * webhook-server command — local development server for webhook testing.
 */
import { dirname, resolve } from "path";
import { fileURLToPath } from "url";
import { Command } from "commander";
import { startWebhookServer } from "../pipeline/webhook-server.js";
const __dirname = dirname(fileURLToPath(import.meta.url));
const ROOT = resolve(__dirname, "..", "..");
export function createWebhookServerCommand() {
    return new Command("webhook-server")
        .description("Start a local webhook development server for testing triggers")
        .option("-p, --port <port>", "Server port", parseInt)
        .action(async (opts) => {
        try {
            startWebhookServer({
                dailyBudget: parseInt(process.env.WEBHOOK_DAILY_BUDGET ?? "20", 10),
                debounceMs: parseInt(process.env.WEBHOOK_DEBOUNCE_MS ?? "10000", 10),
                githubToken: process.env.GITHUB_TOKEN ?? "",
                port: opts.port ?? parseInt(process.env.WEBHOOK_PORT ?? "3333", 10),
                rootDir: ROOT,
            });
        }
        catch (err) {
            process.exitCode = 1;
            if (err instanceof Error)
                console.error(err.message);
        }
    });
}
