"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SpaRedirectionLambda = void 0;
/* tslint:disable:max-classes-per-file */
const aws_cdk_lib_1 = require("aws-cdk-lib");
const constructs_1 = require("constructs");
const path = require("path");
class SpaRedirectionLambda extends constructs_1.Construct {
    constructor(scope, id, props) {
        super(scope, id);
        this.function = new aws_cdk_lib_1.aws_lambda.Function(scope, `${id}Function`, {
            code: aws_cdk_lib_1.aws_lambda.Code.fromAsset(path.join(__dirname, 'src')),
            description: 'Basic rewrite rule to send directory requests to appropriate locations in the SPA.',
            handler: 'handler.handler',
            runtime: aws_cdk_lib_1.aws_lambda.Runtime.NODEJS_22_X,
            timeout: aws_cdk_lib_1.Duration.seconds(10),
            ...props,
        });
        this.behavior = {
            allowedMethods: aws_cdk_lib_1.aws_cloudfront.CloudFrontAllowedMethods.GET_HEAD_OPTIONS,
            compress: true,
            isDefaultBehavior: props.isDefaultBehavior,
            pathPattern: props.pathPattern,
            lambdaFunctionAssociations: [
                {
                    eventType: props.eventType || aws_cdk_lib_1.aws_cloudfront.LambdaEdgeEventType.ORIGIN_REQUEST,
                    lambdaFunction: this.function.currentVersion,
                },
            ],
            minTtl: props.minTtl,
            maxTtl: props.maxTtl,
            defaultTtl: props.defaultTtl,
        };
    }
}
exports.SpaRedirectionLambda = SpaRedirectionLambda;
