import { aggregateAcrossTeams, formatAggregationResult, loopGet, } from "../lib/loop-api.js";
export async function teamInfo(params) {
    const { accountId, teamName } = params;
    const result = await aggregateAcrossTeams(accountId, "team", "loop-team-info", async (apiKey, team) => {
        const data = await loopGet(apiKey, "/team", "loop-team-info", team);
        // /team returns a single object, not an array
        if (data && typeof data === "object" && !Array.isArray(data)) {
            return [data];
        }
        return Array.isArray(data) ? data : [];
    }, { teamName });
    return formatAggregationResult(result, (t) => {
        const name = t.teamName ?? t.clientName ?? "Unknown";
        const client = t.clientName && t.clientName !== t.teamName ? ` (${t.clientName})` : "";
        const addr = t.address1 ? ` — ${t.address1}` : "";
        const phone = t.phoneNumber ? ` | ${t.phoneNumber}` : "";
        const email = t.email ? ` | ${t.email}` : "";
        const web = t.websiteUrl ? ` | ${t.websiteUrl}` : "";
        const lines = [`- **${name}**${client}${addr}${phone}${email}${web}`];
        if (t.members?.length) {
            lines.push(`  Team members (${t.members.length}):`);
            for (const m of t.members) {
                const mName = [m.firstName, m.lastName].filter(Boolean).join(" ");
                const title = m.jobTitle ? ` (${m.jobTitle})` : "";
                const mEmail = m.email ? ` — ${m.email}` : "";
                lines.push(`    - ${mName} [ID: ${m.id}]${title}${mEmail}`);
            }
        }
        return lines.join("\n");
    }, "teams");
}
//# sourceMappingURL=team-info.js.map