"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.addSourceApiAutoMergePermission=exports.addSourceGraphQLPermission=exports.SourceApiAssociation=exports.MergeType=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var appsync_generated_1=()=>{var tmp=require("./appsync.generated");return appsync_generated_1=()=>tmp,tmp},aws_iam_1=()=>{var tmp=require("../../aws-iam");return aws_iam_1=()=>tmp,tmp},core_1=()=>{var tmp=require("../../core");return core_1=()=>tmp,tmp},MergeType;(function(MergeType2){MergeType2.MANUAL_MERGE="MANUAL_MERGE",MergeType2.AUTO_MERGE="AUTO_MERGE"})(MergeType||(exports.MergeType=MergeType={}));class SourceApiAssociation extends core_1().Resource{static fromSourceApiAssociationAttributes(scope,id,attrs){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_appsync_SourceApiAssociationAttributes(attrs)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.fromSourceApiAssociationAttributes),error}class Import extends core_1().Resource{constructor(s,i){super(s,i),this.associationId=core_1().Lazy.stringValue({produce:()=>core_1().Fn.select(3,core_1().Fn.split("/",attrs.associationArn))}),this.associationArn=attrs.associationArn,this.sourceApi=attrs.sourceApi,this.mergedApi=attrs.mergedApi}}return new Import(scope,id)}constructor(scope,id,props){super(scope,id);try{jsiiDeprecationWarnings().aws_cdk_lib_aws_appsync_SourceApiAssociationProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,SourceApiAssociation),error}this.mergeType=props.mergeType??MergeType.AUTO_MERGE,this.mergedApiExecutionRole=props.mergedApiExecutionRole,this.sourceApi=props.sourceApi,this.mergedApi=props.mergedApi,this.association=new(appsync_generated_1()).CfnSourceApiAssociation(this,"Resource",{sourceApiIdentifier:this.sourceApi.arn,mergedApiIdentifier:this.mergedApi.arn,sourceApiAssociationConfig:{mergeType:this.mergeType},description:props.description}),this.sourceApi.addSchemaDependency(this.association),this.associationId=this.association.attrAssociationId,this.associationArn=this.association.attrAssociationArn,addSourceGraphQLPermission(this.association,this.mergedApiExecutionRole),this.mergeType===MergeType.AUTO_MERGE&&addSourceApiAutoMergePermission(this.association,this.mergedApiExecutionRole)}}exports.SourceApiAssociation=SourceApiAssociation,_a=JSII_RTTI_SYMBOL_1,SourceApiAssociation[_a]={fqn:"aws-cdk-lib.aws_appsync.SourceApiAssociation",version:"2.148.1"};function addSourceGraphQLPermission(sourceApiAssociation,mergedApiExecutionRole){return mergedApiExecutionRole.addToPrincipalPolicy(new(aws_iam_1()).PolicyStatement({effect:aws_iam_1().Effect.ALLOW,actions:["appsync:SourceGraphQL"],resources:[sourceApiAssociation.attrSourceApiArn,sourceApiAssociation.attrSourceApiArn.concat("/*")]}))}exports.addSourceGraphQLPermission=addSourceGraphQLPermission;function addSourceApiAutoMergePermission(sourceApiAssociation,mergedApiExecutionRole){return mergedApiExecutionRole.addToPrincipalPolicy(new(aws_iam_1()).PolicyStatement({effect:aws_iam_1().Effect.ALLOW,actions:["appsync:StartSchemaMerge"],resources:[sourceApiAssociation.attrAssociationArn]}))}exports.addSourceApiAutoMergePermission=addSourceApiAutoMergePermission;
