import type { UniDeskConfig } from "./config";
import type { RenderedCliResult } from "./output";
import { runFrontendAuthCommand } from "./frontend-auth";
import { runFrontendPublicExposureCommand } from "./frontend-public-exposure";

export async function runFrontendCommand(config: UniDeskConfig, args: string[]): Promise<Record<string, unknown> | RenderedCliResult> {
  const [scope = "public-exposure"] = args;
  if (scope === "auth") return await runFrontendAuthCommand(config, args.slice(1));
  if (scope === "public-exposure") return await runFrontendPublicExposureCommand(config, args);
  return {
    ok: false,
    error: "unsupported-frontend-command",
    command: "frontend",
    supportedScopes: ["auth", "public-exposure"],
    examples: [
      "bun scripts/cli.ts frontend auth plan",
      "bun scripts/cli.ts frontend auth apply --confirm",
      "bun scripts/cli.ts frontend public-exposure validate",
    ],
  };
}
