"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.WaiterStateMachine=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var constructs_1=()=>{var tmp=require("constructs");return constructs_1=()=>tmp,tmp},aws_iam_1=()=>{var tmp=require("../../../aws-iam");return aws_iam_1=()=>tmp,tmp},aws_logs_1=()=>{var tmp=require("../../../aws-logs");return aws_logs_1=()=>tmp,tmp},aws_stepfunctions_1=()=>{var tmp=require("../../../aws-stepfunctions");return aws_stepfunctions_1=()=>tmp,tmp},core_1=()=>{var tmp=require("../../../core");return core_1=()=>tmp,tmp};class WaiterStateMachine extends constructs_1().Construct{constructor(scope,id,props){super(scope,id);try{jsiiDeprecationWarnings().aws_cdk_lib_custom_resources_WaiterStateMachineProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,WaiterStateMachine),error}const role=new(aws_iam_1()).Role(this,"Role",{assumedBy:new(aws_iam_1()).ServicePrincipal("states.amazonaws.com")});props.isCompleteHandler.grantInvoke(role),props.timeoutHandler.grantInvoke(role);const definition=core_1().Stack.of(this).toJsonString({StartAt:"framework-isComplete-task",States:{"framework-isComplete-task":{End:!0,Retry:[{ErrorEquals:["States.ALL"],IntervalSeconds:props.interval.toSeconds(),MaxAttempts:props.maxAttempts,BackoffRate:props.backoffRate}],Catch:[{ErrorEquals:["States.ALL"],Next:"framework-onTimeout-task"}],Type:"Task",Resource:props.isCompleteHandler.functionArn},"framework-onTimeout-task":{End:!0,Type:"Task",Resource:props.timeoutHandler.functionArn}}});this.isCompleteHandler=props.isCompleteHandler;const resource=new(aws_stepfunctions_1()).CfnStateMachine(this,"Resource",{definitionString:definition,roleArn:role.roleArn,loggingConfiguration:this.renderLoggingConfiguration(role,props.logOptions,props.disableLogging)});resource.node.addDependency(role),this.stateMachineArn=resource.ref}grantStartExecution(identity){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_iam_IGrantable(identity)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.grantStartExecution),error}return aws_iam_1().Grant.addToPrincipal({grantee:identity,actions:["states:StartExecution"],resourceArns:[this.stateMachineArn]})}renderLoggingConfiguration(role,logOptions,disableLogging){return disableLogging?void 0:(role.addToPrincipalPolicy(new(aws_iam_1()).PolicyStatement({actions:["logs:CreateLogDelivery","logs:CreateLogStream","logs:GetLogDelivery","logs:UpdateLogDelivery","logs:DeleteLogDelivery","logs:ListLogDeliveries","logs:PutLogEvents","logs:PutResourcePolicy","logs:DescribeResourcePolicies","logs:DescribeLogGroups"],resources:["*"]})),{destinations:[{cloudWatchLogsLogGroup:{logGroupArn:(logOptions?.destination??new(aws_logs_1()).LogGroup(this,"LogGroup",{logGroupName:`/aws/vendedlogs/states/waiter-state-machine-${this.isCompleteHandler.functionName}-${this.node.addr}`})).logGroupArn}}],includeExecutionData:logOptions?.includeExecutionData??!1,level:logOptions?.level??aws_stepfunctions_1().LogLevel.ERROR})}}exports.WaiterStateMachine=WaiterStateMachine,_a=JSII_RTTI_SYMBOL_1,WaiterStateMachine[_a]={fqn:"aws-cdk-lib.custom_resources.WaiterStateMachine",version:"2.159.0"};
