import { aggregateAcrossTeams, formatAggregationResult, loopGet, } from "../lib/loop-api.js";
export async function propertyListed(params) {
    const { accountId, channel, department = "both", includeSold = false, teamName, limit } = params;
    const result = await aggregateAcrossTeams(accountId, "properties", "loop-property-listed", async (apiKey, team) => {
        const all = [];
        const depts = department === "both" ? ["sales", "lettings"] : [department];
        for (const dept of depts) {
            const path = `/property/residential/${dept}/listed/${channel}`;
            const data = await loopGet(apiKey, path, "loop-property-listed", team);
            if (Array.isArray(data))
                all.push(...data);
        }
        if (includeSold) {
            const soldPath = `/property/residential/sold/${channel}`;
            const soldData = await loopGet(apiKey, soldPath, "loop-property-listed", team);
            if (Array.isArray(soldData))
                all.push(...soldData);
        }
        return all;
    }, { teamName, limitPerTeam: limit ?? 50, limitTotal: limit ?? 200 });
    return formatAggregationResult(result, (p) => {
        const addr = p.displayAddress ?? p.propertyAddress ?? "Unknown address";
        const id = p.propertyId != null ? ` [ID: ${p.propertyId}]` : "";
        const price = p.price ? ` — £${p.price.toLocaleString("en-GB")}` : "";
        const beds = p.bedrooms ? ` ${p.bedrooms}bed` : "";
        const propType = p.propertyType ? ` (${p.propertyType})` : "";
        const status = p.status ? ` [${p.status}]` : "";
        const photos = p.images?.length ? ` ${p.images.length} photo${p.images.length !== 1 ? "s" : ""}` : "";
        return `- ${addr}${id}${price}${beds}${propType}${status}${photos}`;
    }, `${channel} listings`);
}
//# sourceMappingURL=property-listed.js.map