"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SlackApproval = exports.SlackSubscription = void 0;
const aws_cdk_lib_1 = require("aws-cdk-lib");
const constructs_1 = require("constructs");
/**
 * Connects the approval topic from a pipeline with a Slack approval bot
 * @see https://github.com/ndlib/codepipeline-approvals/blob/master/slack_approval.md#slack-approval-bot
 */
class SlackSubscription extends constructs_1.Construct {
    constructor(scope, id, props) {
        super(scope, id);
        const importedNotifyLambdaArn = aws_cdk_lib_1.Fn.importValue(`${props.notifyStackName}:LambdaArn`);
        new aws_cdk_lib_1.aws_sns.Subscription(this, 'NotifyLambdaSNSSubscription', {
            endpoint: importedNotifyLambdaArn,
            protocol: aws_cdk_lib_1.aws_sns.SubscriptionProtocol.LAMBDA,
            topic: props.approvalTopic,
        });
        new aws_cdk_lib_1.aws_lambda.CfnPermission(this, 'NotifyLambdaSNSPermission', {
            action: 'lambda:InvokeFunction',
            principal: 'sns.amazonaws.com',
            sourceArn: props.approvalTopic.topicArn,
            functionName: importedNotifyLambdaArn,
        });
    }
}
exports.SlackSubscription = SlackSubscription;
class SlackApproval extends SlackSubscription {
    constructor(scope, id, props) {
        super(scope, id, props);
    }
}
exports.SlackApproval = SlackApproval;
