export function iamPolicy(policyDocument) { return policyDocument; }
export class Policy {
    document;
    constructor(document = { statement: [], version: "2012-10-17" }) {
        this.document = document;
    }
    grant(action, effect, onResource, statement) {
        this.document.statement = [
            ...(this.document.statement ?? []),
            { action, effect, resource: onResource, ...statement }
        ];
        return this;
    }
    allow(action, onResource, statement) {
        return this.grant(action, 'Allow', onResource, statement);
    }
    deny(action, onResource, statement) {
        return this.grant(action, 'Deny', onResource, statement);
    }
    static allow(action, onResource, statement) {
        return new Policy().allow(action, onResource, statement);
    }
    static deny(action, onResource, statement) {
        return new Policy().deny(action, onResource, statement);
    }
}
export class Iam {
    roleLike;
    constructor(roleLike) {
        this.roleLike = roleLike;
    }
    add(policyName, policy) {
        this.roleLike.properties.policies = [
            ...(this.roleLike.properties.policies ?? []),
            { policyName, policyDocument: policy.document }
        ];
        return this;
    }
    withAssumeRolePolicyStatement(action, effect, rest) {
        const current = this.roleLike.properties.assumeRolePolicyDocument ?? { version: "2012-10-17", statement: [] };
        this.roleLike.properties.assumeRolePolicyDocument = {
            ...current,
            statement: [...current.statement, { action, effect, ...rest }]
        };
        return this;
    }
    withManagedPolicies(...arns) {
        this.roleLike.properties.managedPolicyArns = arns;
        return this;
    }
    static policy(creator) {
        return creator();
    }
    static from(roleLike) {
        return new Iam(roleLike);
    }
}
