"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.PolicyDocument=void 0;const jsiiDeprecationWarnings=require("../../.warnings.jsii.js"),JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti"),cdk=require("../../core"),cxapi=require("../../cx-api"),policy_statement_1=require("./policy-statement"),postprocess_policy_document_1=require("./private/postprocess-policy-document");class PolicyDocument{constructor(props={}){this.statements=new Array;try{jsiiDeprecationWarnings.aws_cdk_lib_aws_iam_PolicyDocumentProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.constructor),error}this.creationStack=cdk.captureStackTrace(),this.autoAssignSids=!!props.assignSids,this.minimize=props.minimize,this.addStatements(...props.statements||[])}static fromJson(obj){var _b;const newPolicyDocument=new PolicyDocument,statement=(_b=obj.Statement)!==null&&_b!==void 0?_b:[];if(statement&&!Array.isArray(statement))throw new Error("Statement must be an array");return newPolicyDocument.addStatements(...obj.Statement.map(s=>policy_statement_1.PolicyStatement.fromJson(s))),newPolicyDocument}resolve(context){var _b,_c;try{jsiiDeprecationWarnings.aws_cdk_lib_IResolveContext(context)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.resolve),error}return context.registerPostProcessor(new postprocess_policy_document_1.PostProcessPolicyDocument(this.autoAssignSids,(_c=(_b=this.minimize)!==null&&_b!==void 0?_b:cdk.FeatureFlags.of(context.scope).isEnabled(cxapi.IAM_MINIMIZE_POLICIES))!==null&&_c!==void 0?_c:!1)),this.render()}get isEmpty(){return this.statements.length===0}get statementCount(){return this.statements.length}addStatements(...statement){try{jsiiDeprecationWarnings.aws_cdk_lib_aws_iam_PolicyStatement(statement)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.addStatements),error}this.statements.push(...statement)}toString(){return cdk.Token.asString(this,{displayHint:"PolicyDocument"})}toJSON(){return this.render()}validateForAnyPolicy(){const errors=new Array;for(const statement of this.statements)errors.push(...statement.validateForAnyPolicy());return errors}validateForResourcePolicy(){const errors=new Array;for(const statement of this.statements)errors.push(...statement.validateForResourcePolicy());return errors}validateForIdentityPolicy(){const errors=new Array;for(const statement of this.statements)errors.push(...statement.validateForIdentityPolicy());return errors}render(){return this.isEmpty?void 0:{Statement:this.statements.map(s=>s.toStatementJson()),Version:"2012-10-17"}}}exports.PolicyDocument=PolicyDocument,_a=JSII_RTTI_SYMBOL_1,PolicyDocument[_a]={fqn:"aws-cdk-lib.aws_iam.PolicyDocument",version:"2.24.1"};
//# sourceMappingURL=policy-document.js.map
