// @bun
import {
  ensureJsonOnlyFormat
} from "./chunk-5zqmmchg.js";
import {
  createCliLogger
} from "./chunk-t993tmz7.js";
import"./chunk-px7fts59.js";
import {
  AdkError,
  AgentProject,
  SecretsManager,
  validateSecretName
} from "./chunk-7krp2mgz.js";
import"./chunk-np5wcwfv.js";
import"./chunk-je8v6rhj.js";
import"./chunk-6w0knnta.js";
import"./chunk-w15xmtkn.js";
import"./chunk-3sd5p4qp.js";
import"./chunk-nh2akp42.js";
import"./chunk-kat1bv74.js";
import"./chunk-2a5b6azq.js";
import"./chunk-s8cp3qe6.js";
import"./chunk-fv5teh9w.js";
import"./chunk-8ab2w9a1.js";
import"./chunk-3xrpxgq4.js";
import"./chunk-w346ejn9.js";
import"./chunk-n8gath4k.js";
import"./chunk-v3ens42y.js";
import"./chunk-8839jtgk.js";
import"./chunk-s2akeqpw.js";
import"./chunk-6771vrjp.js";
import"./chunk-g8mm42v1.js";
import"./chunk-0q5d80bn.js";
import"./chunk-300xaact.js";
import"./chunk-b8c41yvb.js";
import"./chunk-jsqe5am4.js";
import"./chunk-m4c14gcg.js";
import"./chunk-gspjbr79.js";
import"./chunk-wesykvkp.js";
import"./chunk-gzj56z73.js";
import"./chunk-dhs2bg35.js";

// src/commands/adk-secret.ts
import path from "path";
async function adkSecret(options = {}) {
  ensureJsonOnlyFormat(options.format);
  const logger = createCliLogger({ format: options.format });
  const isJson = options.format === "json";
  const projectPath = path.resolve(process.cwd());
  const project = await AgentProject.load(projectPath);
  const manager = new SecretsManager(projectPath);
  const declaredSecrets = project.config?.secrets ?? {};
  if (Object.keys(declaredSecrets).length === 0) {
    if (isJson) {
      logger.info("").result({ success: true, secrets: [] });
    } else {
      logger.info("No secrets declared in agent.config.ts");
    }
    return;
  }
  const devSecrets = await manager.getAll("dev", declaredSecrets);
  const prodSecrets = await manager.getAll("prod", declaredSecrets);
  const buildList = (stored) => Object.entries(declaredSecrets).map(([name, def]) => ({
    name,
    declared: true,
    set: name in stored,
    optional: def.optional ?? false,
    description: def.description ?? ""
  }));
  const devList = buildList(devSecrets);
  const prodList = buildList(prodSecrets);
  const printList = (label, list) => {
    logger.info(`
\uD83D\uDD11 Secrets (${label})
`, "blue");
    for (const secret of list) {
      const status = secret.set ? "\u2713 set" : "\u2717 not set";
      const optionalTag = secret.optional ? " (optional)" : "";
      const descTag = secret.description ? ` \u2014 ${secret.description}` : "";
      const color = secret.set ? "green" : "yellow";
      logger.info(`  ${secret.name}: ${status}${optionalTag}${descTag}`, color);
    }
  };
  printList("dev", devList);
  printList("prod", prodList);
  logger.newline();
  logger.info("").result({ success: true, dev: devList, prod: prodList });
}
async function adkSecretSet(key, value, options = {}) {
  ensureJsonOnlyFormat(options.format);
  const logger = createCliLogger({ format: options.format });
  const projectPath = path.resolve(process.cwd());
  const env = options.prod ? "prod" : "dev";
  const validation = validateSecretName(key);
  if (!validation.valid) {
    throw new AdkError({ code: "INVALID_SECRET", message: validation.error, expected: true });
  }
  const project = await AgentProject.load(projectPath);
  const declaredSecrets = project.config?.secrets ?? {};
  if (!(key in declaredSecrets)) {
    const available = Object.keys(declaredSecrets);
    throw new AdkError({
      code: "INVALID_SECRET",
      message: available.length > 0 ? `Secret "${key}" is not declared in agent.config.ts. Available secrets: ${available.join(", ")}` : `Secret "${key}" is not declared in agent.config.ts. Add it to the secrets field in your config first.`,
      expected: true
    });
  }
  const normalizedValue = value.trim();
  if (normalizedValue.length === 0) {
    throw new AdkError({
      code: "INVALID_SECRET",
      message: `Invalid value for secret "${key}": value cannot be empty`,
      expected: true
    });
  }
  const manager = new SecretsManager(projectPath);
  await manager.set(key, normalizedValue, env);
  logger.info(`\u2713 Secret ${key} set (${env})`, "green").result({ success: true, key });
}
async function adkSecretDelete(key, options = {}) {
  ensureJsonOnlyFormat(options.format);
  const logger = createCliLogger({ format: options.format });
  const projectPath = path.resolve(process.cwd());
  const env = options.prod ? "prod" : "dev";
  const manager = new SecretsManager(projectPath);
  await manager.delete(key, env);
  logger.info(`\u2713 Secret ${key} deleted (${env})`, "green").result({ success: true, key });
}
export {
  adkSecretSet,
  adkSecretDelete,
  adkSecret
};
