"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApiGatewayErrorRatesMetric = void 0;
const aws_cdk_lib_1 = require("aws-cdk-lib");
const _1 = require(".");
class ApiGatewayErrorRatesMetric {
    constructor(props) {
        var _a, _b, _c;
        const idx = (_a = props.metricIdx) !== null && _a !== void 0 ? _a : 0;
        const errors4xx = new aws_cdk_lib_1.aws_cloudwatch.Metric((0, _1.apiGatewayMetricPropsToMetricProps)(props, '4XXError', '4xx', aws_cdk_lib_1.aws_cloudwatch.Statistic.SUM));
        const errors5xx = new aws_cdk_lib_1.aws_cloudwatch.Metric((0, _1.apiGatewayMetricPropsToMetricProps)(props, '5XXError', '5xx', aws_cdk_lib_1.aws_cloudwatch.Statistic.SUM));
        const requests = new aws_cdk_lib_1.aws_cloudwatch.Metric((0, _1.apiGatewayMetricPropsToMetricProps)(props, 'Count', 'Requests', aws_cdk_lib_1.aws_cloudwatch.Statistic.SUM));
        this.rate4xx = new aws_cdk_lib_1.aws_cloudwatch.MathExpression({
            label: (_b = props.label) !== null && _b !== void 0 ? _b : '4xx',
            color: props.color,
            expression: `errors4xx_${idx}/requests_${idx}*100`,
            period: props.period,
            usingMetrics: {
                [`requests_${idx}`]: requests,
                [`errors4xx_${idx}`]: errors4xx,
            },
        });
        this.rate5xx = new aws_cdk_lib_1.aws_cloudwatch.MathExpression({
            label: (_c = props.label) !== null && _c !== void 0 ? _c : '5xx',
            color: props.color,
            expression: `errors5xx_${idx}/requests_${idx}*100`,
            period: props.period,
            usingMetrics: {
                [`requests_${idx}`]: requests,
                [`errors5xx_${idx}`]: errors5xx,
            },
        });
    }
}
exports.ApiGatewayErrorRatesMetric = ApiGatewayErrorRatesMetric;
