// (C) 2022-2026 GoodData Corporation
import { getMeasureFormat, getMeasureTitle } from "./getters.js";
import { transformAlertExecutionByMetric } from "./transformation.js";
/**
 * @internal
 */
export function createDefaultAlert(filters, metrics, measure, notificationChannelId, currentUser, measureFormatMap, comparisonOperator = "GREATER_THAN", schedule, visibleWidgetFilters, widgetLocalId, dashboardId, widgetName, targetTabIdentifier) {
    if (!measure) {
        return undefined;
    }
    const condition = {
        type: "comparison",
        left: {
            id: measure.measure.measure.localIdentifier,
            format: getMeasureFormat(measure.measure, measureFormatMap),
            title: getMeasureTitle(measure.measure),
        },
        operator: comparisonOperator,
        right: undefined,
    };
    const execution = {
        attributes: [],
        measures: [measure.measure],
        filters,
    };
    const trigger = {
        state: "ACTIVE",
    };
    return {
        type: "automation",
        title: "",
        notificationChannel: notificationChannelId,
        dashboard: dashboardId ? { id: dashboardId } : undefined,
        alert: {
            trigger,
            condition,
            ...transformAlertExecutionByMetric(metrics, { alert: { execution, condition, trigger } }, condition, measure, undefined),
        },
        ...(schedule ? { schedule } : {}),
        recipients: [currentUser],
        metadata: {
            widget: widgetLocalId,
            visibleFilters: visibleWidgetFilters,
            ...(targetTabIdentifier ? { targetTabIdentifier } : {}),
        },
        details: {
            widgetName: widgetName,
        },
    };
}
//# sourceMappingURL=convertors.js.map