"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SLOAlarmsDashboard = void 0;
const aws_cdk_lib_1 = require("aws-cdk-lib");
const api_availability_widget_1 = require("./api-availability-widget");
const api_latency_widget_1 = require("./api-latency-widget");
const appsync_availability_widget_1 = require("./appsync-availability-widget");
const appsync_latency_widget_1 = require("./appsync-latency-widget");
const cloudfront_availability_widget_1 = require("./cloudfront-availability-widget");
const cloudfront_latency_widget_1 = require("./cloudfront-latency-widget");
const custom_availability_widget_1 = require("./custom-availability-widget");
const custom_latency_widget_1 = require("./custom-latency-widget");
const elasticsearch_availability_widget_1 = require("./elasticsearch-availability-widget");
const elasticsearch_latency_widget_1 = require("./elasticsearch-latency-widget");
const windows_1 = require("./windows");
/**
 * Creates dashboard of multiwindow alarms from a list of slo objects.
 */
class SLOAlarmsDashboard extends aws_cdk_lib_1.aws_cloudwatch.Dashboard {
    constructor(scope, id, props) {
        const widgets = props.slos.reduce((result, slo) => {
            // Use standard alarm windows, plus the thirty day window, since the purpose of this dash is to see
            // how well the alarms are predicting when the 30 day window will be exceeded
            const windows = [...windows_1.Windows.standardAlarmWindows, windows_1.Windows.thirtyDays];
            switch (slo.type) {
                case 'ApiAvailability':
                    result.push(SLOAlarmsDashboard.apiAvailabilityAlarmsRow(windows, slo));
                    break;
                case 'ApiLatency':
                    result.push(SLOAlarmsDashboard.apiLatencyAlarmsRow(windows, slo));
                    break;
                case 'AppSyncAvailability':
                    result.push(SLOAlarmsDashboard.appSyncAvailabilityAlarmsRow(windows, slo));
                    break;
                case 'AppSyncLatency':
                    result.push(SLOAlarmsDashboard.appSyncLatencyAlarmsRow(windows, slo));
                    break;
                case 'CloudfrontAvailability':
                    result.push(SLOAlarmsDashboard.cloudfrontAvailabilityAlarmsRow(windows, slo));
                    break;
                case 'CloudfrontLatency':
                    result.push(SLOAlarmsDashboard.cloudfrontLatencyAlarmsRow(windows, slo));
                    break;
                case 'CustomAvailability':
                    result.push(SLOAlarmsDashboard.customAvailabilityAlarmsRow(windows, slo));
                    break;
                case 'CustomLatency':
                    result.push(SLOAlarmsDashboard.customLatencyAlarmsRow(windows, slo));
                    break;
                case 'ElasticSearchAvailability':
                    result.push(SLOAlarmsDashboard.elasticSearchAvailabilityAlarmsRow(windows, slo));
                    break;
                case 'ElasticSearchLatency':
                    result.push(SLOAlarmsDashboard.elasticSearchLatencyAlarmsRow(windows, slo));
                    break;
                default:
                    throw new Error(`AlarmsDashboard creation encountered an unknown type for slo: ${JSON.stringify(slo)}.`);
            }
            return result;
        }, []);
        const defaultProps = {
            widgets,
            start: '-P360D',
        };
        super(scope, id, { ...defaultProps, ...props });
    }
}
exports.SLOAlarmsDashboard = SLOAlarmsDashboard;
// Creates an array of ApiAvailabilityWidgets for each window we are using
SLOAlarmsDashboard.apiAvailabilityAlarmsRow = (windows, slo) => {
    return windows.map(sloWindow => new api_availability_widget_1.ApiAvailabilityWidget({
        ...slo,
        sloWindow,
        showBurnRateThreshold: true,
        addPeriodToTitle: true,
    }));
};
// Creates an array of ApiLatencyWidgets for each window we are using
SLOAlarmsDashboard.apiLatencyAlarmsRow = (windows, slo) => {
    return windows.map(sloWindow => new api_latency_widget_1.ApiLatencyWidget({
        ...slo,
        sloWindow,
        showBurnRateThreshold: true,
        addPeriodToTitle: true,
    }));
};
// Creates an array of AppSyncAvailabilityWidgets for each window we are using
SLOAlarmsDashboard.appSyncAvailabilityAlarmsRow = (windows, slo) => {
    return windows.map(sloWindow => new appsync_availability_widget_1.AppSyncAvailabilityWidget({
        ...slo,
        sloWindow,
        showBurnRateThreshold: true,
        addPeriodToTitle: true,
    }));
};
// Creates an array of AppSyncLatencyWidgets for each window we are using
SLOAlarmsDashboard.appSyncLatencyAlarmsRow = (windows, slo) => {
    return windows.map(sloWindow => new appsync_latency_widget_1.AppSyncLatencyWidget({
        ...slo,
        sloWindow,
        showBurnRateThreshold: true,
        addPeriodToTitle: true,
    }));
};
// Creates an array of CloudfrontAvailabilityWidgets for each window we are using
SLOAlarmsDashboard.cloudfrontAvailabilityAlarmsRow = (windows, slo) => {
    return windows.map(sloWindow => new cloudfront_availability_widget_1.CloudfrontAvailabilityWidget({
        ...slo,
        sloWindow,
        showBurnRateThreshold: true,
        addPeriodToTitle: true,
    }));
};
// Creates an array of CloudfrontLatencyWidgets for each window we are using
SLOAlarmsDashboard.cloudfrontLatencyAlarmsRow = (windows, slo) => {
    return windows.map(sloWindow => new cloudfront_latency_widget_1.CloudfrontLatencyWidget({
        ...slo,
        sloWindow,
        showBurnRateThreshold: true,
        addPeriodToTitle: true,
    }));
};
// Creates an array of CustomAvailabilityWidgets for each window we are using
SLOAlarmsDashboard.customAvailabilityAlarmsRow = (windows, slo) => {
    return windows.map(sloWindow => new custom_availability_widget_1.CustomAvailabilityWidget({
        ...slo,
        sloWindow,
        showBurnRateThreshold: true,
        addPeriodToTitle: true,
    }));
};
// Creates an array of ApiLatencyWidgets for each window we are using
SLOAlarmsDashboard.customLatencyAlarmsRow = (windows, slo) => {
    return windows.map(sloWindow => new custom_latency_widget_1.CustomLatencyWidget({
        ...slo,
        sloWindow,
        showBurnRateThreshold: true,
        addPeriodToTitle: true,
    }));
};
// Creates an array of ElasticSearchAvailabilityWidgets for each window we are using
SLOAlarmsDashboard.elasticSearchAvailabilityAlarmsRow = (windows, slo) => {
    return windows.map(sloWindow => new elasticsearch_availability_widget_1.ElasticSearchAvailabilityWidget({
        ...slo,
        sloWindow,
        showBurnRateThreshold: true,
        addPeriodToTitle: true,
    }));
};
// Creates an array of ElasticSearchLatencyWidgets for each window we are using
SLOAlarmsDashboard.elasticSearchLatencyAlarmsRow = (windows, slo) => {
    return windows.map(sloWindow => new elasticsearch_latency_widget_1.ElasticSearchLatencyWidget({
        ...slo,
        sloWindow,
        showBurnRateThreshold: true,
        addPeriodToTitle: true,
    }));
};
