"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.BucketPolicy=void 0;const jsiiDeprecationWarnings=require("../../.warnings.jsii.js"),JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti"),bucket_1=require("./bucket"),s3_generated_1=require("./s3.generated"),aws_iam_1=require("../../aws-iam"),core_1=require("../../core"),cfn_reference_1=require("../../core/lib/private/cfn-reference");class BucketPolicy extends core_1.Resource{static fromCfnBucketPolicy(cfnBucketPolicy){try{jsiiDeprecationWarnings.aws_cdk_lib_aws_s3_CfnBucketPolicy(cfnBucketPolicy)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.fromCfnBucketPolicy),error}const id="@FromCfnBucketPolicy",existing=cfnBucketPolicy.node.tryFindChild(id);if(existing)return existing;let bucket;if(core_1.Token.isUnresolved(cfnBucketPolicy.bucket)){const bucketIResolvable=core_1.Tokenization.reverse(cfnBucketPolicy.bucket);if(bucketIResolvable instanceof cfn_reference_1.CfnReference){const cfnElement=bucketIResolvable.target;cfnElement instanceof s3_generated_1.CfnBucket&&(bucket=bucket_1.Bucket.fromCfnBucket(cfnElement))}}bucket||(bucket=bucket_1.Bucket.fromBucketName(cfnBucketPolicy,"@FromCfnBucket",cfnBucketPolicy.bucket));const ret=new class extends BucketPolicy{constructor(){super(...arguments),this.document=aws_iam_1.PolicyDocument.fromJson(cfnBucketPolicy.policyDocument)}}(cfnBucketPolicy,id,{bucket});return bucket.policy=ret,ret}constructor(scope,id,props){super(scope,id),this.document=new aws_iam_1.PolicyDocument;try{jsiiDeprecationWarnings.aws_cdk_lib_aws_s3_BucketPolicyProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,BucketPolicy),error}this.bucket=props.bucket,this.resource=new s3_generated_1.CfnBucketPolicy(this,"Resource",{bucket:this.bucket.bucketName,policyDocument:this.document}),props.removalPolicy&&this.resource.applyRemovalPolicy(props.removalPolicy)}applyRemovalPolicy(removalPolicy){try{jsiiDeprecationWarnings.aws_cdk_lib_RemovalPolicy(removalPolicy)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.applyRemovalPolicy),error}this.resource.applyRemovalPolicy(removalPolicy)}}exports.BucketPolicy=BucketPolicy,_a=JSII_RTTI_SYMBOL_1,BucketPolicy[_a]={fqn:"aws-cdk-lib.aws_s3.BucketPolicy",version:"2.96.1"};
