import { loopGet, loopPost, withTeamKey } from "../lib/loop-api.js";
export async function customerPreferences(params) {
    const { accountId, teamName, personCode, action } = params;
    if (action === "read") {
        const result = await withTeamKey(accountId, teamName, "customer", "loop-customer-preferences", async (apiKey) => {
            return loopGet(apiKey, `/customer/preferences/${personCode}`, "loop-customer-preferences", teamName);
        });
        if (!result || (Array.isArray(result) && result.length === 0)) {
            return `No preferences found for person ${personCode} via team "${teamName}".`;
        }
        return JSON.stringify(result, null, 2);
    }
    if (action === "write") {
        if (!params.preferences) {
            throw new Error("preferences object is required when action is 'write'.");
        }
        await withTeamKey(accountId, teamName, "customer", "loop-customer-preferences", async (apiKey) => {
            return loopPost(apiKey, `/customer/preferences/${personCode}`, params.preferences, "loop-customer-preferences", teamName);
        });
        return `Preferences updated for person ${personCode} via team "${teamName}".`;
    }
    throw new Error(`Unknown action: ${action}. Use "read" or "write".`);
}
//# sourceMappingURL=customer-preferences.js.map