"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GraphqlApiErrorRatesMetric = void 0;
const aws_cdk_lib_1 = require("aws-cdk-lib");
const _1 = require(".");
class GraphqlApiErrorRatesMetric {
    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.graphqlApiMetricPropsToMetricProps)(props, '4XXError', '4XX Errors', aws_cdk_lib_1.aws_cloudwatch.Statistic.SUM));
        const errors5xx = new aws_cdk_lib_1.aws_cloudwatch.Metric((0, _1.graphqlApiMetricPropsToMetricProps)(props, '5XXError', '5XX Errors', aws_cdk_lib_1.aws_cloudwatch.Statistic.SUM));
        const requests = new _1.GraphqlApiRequestsMetric(props);
        this.rate4xx = new aws_cdk_lib_1.aws_cloudwatch.MathExpression({
            label: (_b = props.label) !== null && _b !== void 0 ? _b : '4xx',
            color: props.color,
            period: props.period,
            expression: `errors4xx_${idx}/requests_${idx}*100`,
            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,
            period: props.period,
            expression: `errors5xx_${idx}/requests_${idx}*100`,
            usingMetrics: {
                [`requests_${idx}`]: requests,
                [`errors5xx_${idx}`]: errors5xx,
            },
        });
    }
}
exports.GraphqlApiErrorRatesMetric = GraphqlApiErrorRatesMetric;
