import { loadTeamKeys } from "../lib/loop-api.js";

export async function keyList(params: {
  accountId: string;
}): Promise<string> {
  const keys = await loadTeamKeys(params.accountId);

  if (keys.length === 0) {
    return "No Loop teams registered. Use loop-key-register to add team API keys.";
  }

  const lines = keys.map((k) => {
    const perms = k.permissions.join(", ");
    const addr = k.teamAddress ? ` — ${k.teamAddress}` : "";
    return `- **${k.teamName}**${addr} (permissions: ${perms}, registered: ${k.createdAt})`;
  });

  return `${keys.length} Loop team(s) registered:\n\n${lines.join("\n")}`;
}
