import { loopPost, withTeamKey } from "../lib/loop-api.js";
export async function viewingUpdate(params) {
    const { accountId, teamName, viewingId, department, action, text, feedbackParty } = params;
    if (action === "feedback" && !feedbackParty) {
        throw new Error("feedbackParty is required when action is 'feedback'. Use: buyer, seller, renter, or landlord.");
    }
    await withTeamKey(accountId, teamName, "viewings", "loop-viewing-update", async (apiKey) => {
        const suffix = action === "note"
            ? "note"
            : `${feedbackParty}-feedback`;
        const path = `/residential/${department}/viewings/${viewingId}/${suffix}`;
        // Loop expects the text as a StringResponse body
        return loopPost(apiKey, path, { result: text }, "loop-viewing-update", teamName);
    });
    const actionLabel = action === "note" ? "Note added" : `${feedbackParty} feedback recorded`;
    return `${actionLabel} for viewing ${viewingId} (${department}) via team "${teamName}".`;
}
//# sourceMappingURL=viewing-update.js.map