import { aggregateAcrossTeams, formatAggregationResult, loopGet, } from "../lib/loop-api.js";
export async function marketingMatchDetail(params) {
    const { accountId, propertyId, department, includeTeamProfile = false, teamName } = params;
    const result = await aggregateAcrossTeams(accountId, "marketing", "loop-marketing-match", async (apiKey, team) => {
        const prefix = department === "lettings" ? "/marketing/rentals" : "/marketing";
        const path = `${prefix}/matching/${propertyId}`;
        const data = await loopGet(apiKey, path, "loop-marketing-match", team);
        if (data && typeof data === "object" && !Array.isArray(data)) {
            if (includeTeamProfile) {
                const profilePath = `${prefix}/matching/${propertyId}/team-profile`;
                const profile = await loopGet(apiKey, profilePath, "loop-marketing-match", team).catch(() => null);
                if (profile) {
                    data._teamProfile = profile;
                }
            }
            return [data];
        }
        return [];
    }, { teamName });
    return formatAggregationResult(result, (p) => {
        const lines = [`**${p.address ?? "Unknown address"}**`];
        if (p.price)
            lines.push(`Price: £${p.price.toLocaleString("en-GB")}`);
        if (p.type)
            lines.push(`Type: ${p.type}`);
        if (p.bedrooms)
            lines.push(`Bedrooms: ${p.bedrooms}`);
        if (p.status)
            lines.push(`Status: ${p.status}`);
        if (p.description)
            lines.push(`\n${p.description}`);
        const profile = p._teamProfile;
        if (profile) {
            lines.push(`\n**Team:** ${profile.name ?? ""} — ${profile.address ?? ""} | ${profile.phone ?? ""} | ${profile.email ?? ""}`);
        }
        return lines.join("\n");
    }, "matching property details");
}
//# sourceMappingURL=marketing-match.js.map