import { get, post } from "./serviceHelper";
let cachedRuleElements;
export async function getRuleElements() {
    if (cachedRuleElements) {
        return cachedRuleElements;
    }
    const response = await get("/parhelia/rules/elements");
    cachedRuleElements = response.data || [];
    return cachedRuleElements;
}
export async function getRulesForComponent(pageItem, componentId, sessionId, signal) {
    const response = await post("/parhelia/rules/get", {
        pageItem,
        componentId,
    }, sessionId, signal);
    return (response.data || {
        rules: [],
        unsupported: false,
        unsupportedReasons: [],
    });
}
export async function setActiveRuleForComponent(pageItem, componentId, ruleId, sessionId) {
    const response = await post("/parhelia/rules/active", {
        pageItem,
        componentId,
        ruleId: ruleId || "",
    }, sessionId);
    if (response.type === "error" || response.type === "unauthorized") {
        throw new Error(response.summary || "Failed to set active personalization rule");
    }
}
//# sourceMappingURL=personalizationService.js.map