"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.CfnTablePropsMixin = exports.CfnGlobalTablePropsMixin = void 0;
const jsiiDeprecationWarnings = require("../../../.warnings.jsii.js");
const JSII_RTTI_SYMBOL_1 = Symbol.for("jsii.rtti");
/* eslint-disable @stylistic/max-len, eol-last */
const cdk = __importStar(require("aws-cdk-lib/core"));
const service = __importStar(require("aws-cdk-lib/aws-dynamodb"));
/**
 * The `AWS::DynamoDB::GlobalTable` resource enables you to create and manage a Version 2019.11.21 global table. This resource cannot be used to create or manage a Version 2017.11.29 global table. For more information, see [Global tables](https://docs.aws.amazon.com//amazondynamodb/latest/developerguide/GlobalTables.html) .
 *
 * > You cannot convert a resource of type `AWS::DynamoDB::Table` into a resource of type `AWS::DynamoDB::GlobalTable` by changing its type in your template. *Doing so might result in the deletion of your DynamoDB table.*
 * >
 * > You can instead use the GlobalTable resource to create a new table in a single Region. This will be billed the same as a single Region table. If you later update the stack to add other Regions then Global Tables pricing will apply.
 *
 * You should be aware of the following behaviors when working with DynamoDB global tables.
 *
 * - The IAM Principal executing the stack operation must have the permissions listed below in all regions where you plan to have a global table replica. The IAM Principal's permissions should not have restrictions based on IP source address. Some global tables operations (for example, adding a replica) are asynchronous, and require that the IAM Principal is valid until they complete. You should not delete the Principal (user or IAM role) until CloudFormation has finished updating your stack.
 *
 * - `application-autoscaling:DeleteScalingPolicy`
 * - `application-autoscaling:DeleteScheduledAction`
 * - `application-autoscaling:DeregisterScalableTarget`
 * - `application-autoscaling:DescribeScalableTargets`
 * - `application-autoscaling:DescribeScalingPolicies`
 * - `application-autoscaling:PutScalingPolicy`
 * - `application-autoscaling:PutScheduledAction`
 * - `application-autoscaling:RegisterScalableTarget`
 * - `dynamodb:BatchWriteItem`
 * - `dynamodb:CreateGlobalTableWitness`
 * - `dynamodb:CreateTable`
 * - `dynamodb:CreateTableReplica`
 * - `dynamodb:DeleteGlobalTableWitness`
 * - `dynamodb:DeleteItem`
 * - `dynamodb:DeleteTable`
 * - `dynamodb:DeleteTableReplica`
 * - `dynamodb:DescribeContinuousBackups`
 * - `dynamodb:DescribeContributorInsights`
 * - `dynamodb:DescribeTable`
 * - `dynamodb:DescribeTableReplicaAutoScaling`
 * - `dynamodb:DescribeTimeToLive`
 * - `dynamodb:DisableKinesisStreamingDestination`
 * - `dynamodb:EnableKinesisStreamingDestination`
 * - `dynamodb:GetItem`
 * - `dynamodb:ListTables`
 * - `dynamodb:ListTagsOfResource`
 * - `dynamodb:PutItem`
 * - `dynamodb:Query`
 * - `dynamodb:Scan`
 * - `dynamodb:TagResource`
 * - `dynamodb:UntagResource`
 * - `dynamodb:UpdateContinuousBackups`
 * - `dynamodb:UpdateContributorInsights`
 * - `dynamodb:UpdateItem`
 * - `dynamodb:UpdateTable`
 * - `dynamodb:UpdateTableReplicaAutoScaling`
 * - `dynamodb:UpdateTimeToLive`
 * - `iam:CreateServiceLinkedRole`
 * - `kms:CreateGrant`
 * - `kms:DescribeKey`
 * - When using provisioned billing mode, CloudFormation will create an auto scaling policy on each of your replicas to control their write capacities. You must configure this policy using the `WriteProvisionedThroughputSettings` property. CloudFormation will ensure that all replicas have the same write capacity auto scaling property. You cannot directly specify a value for write capacity for a global table.
 * - If your table uses provisioned capacity, you must configure auto scaling directly in the `AWS::DynamoDB::GlobalTable` resource. You should not configure additional auto scaling policies on any of the table replicas or global secondary indexes, either via API or via `AWS::ApplicationAutoScaling::ScalableTarget` or `AWS::ApplicationAutoScaling::ScalingPolicy` . Doing so might result in unexpected behavior and is unsupported.
 * - In AWS CloudFormation , each global table is controlled by a single stack, in a single region, regardless of the number of replicas. When you deploy your template, CloudFormation will create/update all replicas as part of a single stack operation. You should not deploy the same `AWS::DynamoDB::GlobalTable` resource in multiple regions. Doing so will result in errors, and is unsupported. If you deploy your application template in multiple regions, you can use conditions to only create the resource in a single region. Alternatively, you can choose to define your `AWS::DynamoDB::GlobalTable` resources in a stack separate from your application stack, and make sure it is only deployed to a single region.
 *
 * @cloudformationResource AWS::DynamoDB::GlobalTable
 * @mixin true
 * @stability external
 * @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-globaltable.html
 */
class CfnGlobalTablePropsMixin extends cdk.Mixin {
    static [JSII_RTTI_SYMBOL_1] = { fqn: "@aws-cdk/cfn-property-mixins.aws_dynamodb.CfnGlobalTablePropsMixin", version: "2.258.1" };
    static CFN_PROPERTY_KEYS = ["attributeDefinitions", "billingMode", "globalSecondaryIndexes", "globalTableSourceArn", "globalTableWitnesses", "keySchema", "localSecondaryIndexes", "multiRegionConsistency", "readOnDemandThroughputSettings", "readProvisionedThroughputSettings", "replicas", "sseSpecification", "streamSpecification", "tableName", "timeToLiveSpecification", "warmThroughput", "writeOnDemandThroughputSettings", "writeProvisionedThroughputSettings"];
    props;
    strategy;
    /**
     * Create a mixin to apply properties to `AWS::DynamoDB::GlobalTable`.
     *
     * @param props L1 properties to apply
     * @param options Mixin options
     */
    constructor(props, options = {}) {
        super();
        try {
            jsiiDeprecationWarnings._aws_cdk_cfn_property_mixins_aws_dynamodb_CfnGlobalTableMixinProps(props);
            jsiiDeprecationWarnings._aws_cdk_cfn_property_mixins_CfnPropertyMixinOptions(options);
        }
        catch (error) {
            if (process.env.JSII_DEBUG !== "1" && error.name === "DeprecationError") {
                Error.captureStackTrace(error, CfnGlobalTablePropsMixin);
            }
            throw error;
        }
        this.props = {
            ...props,
            ...flattenCfnGlobalTableMixinProps(props)
        };
        this.strategy = (options.strategy ?? cdk.PropertyMergeStrategy.combine());
    }
    /**
     * Check if this mixin supports the given construct
     */
    supports(construct) {
        return (cdk.CfnResource.isCfnResource(construct) && service.CfnGlobalTable.isCfnGlobalTable(construct));
    }
    /**
     * Apply the mixin properties to the construct
     */
    applyTo(construct) {
        if (this.supports(construct)) {
            this.strategy.apply(construct, this.props, CfnGlobalTablePropsMixin.CFN_PROPERTY_KEYS);
        }
    }
}
exports.CfnGlobalTablePropsMixin = CfnGlobalTablePropsMixin;
// @ts-ignore TS6133
function flattenCfnGlobalTablePropsMixinReplicaSSESpecificationProperty(props) {
    if (cdk.isResolvableObject(props))
        return props;
    return {
        kmsMasterKeyId: (!props.kmsMasterKeyId ? undefined : cdk.getRefProperty(props.kmsMasterKeyId?.keyRef, 'keyArn') ?? cdk.getRefProperty(props.kmsMasterKeyId?.keyRef, 'keyId') ?? cdk.getRefProperty(props.kmsMasterKeyId?.aliasRef, 'aliasName') ?? cdk.ensureStringOrUndefined(props.kmsMasterKeyId, "kmsMasterKeyId", "kms.IKeyRef | kms.IAliasRef | string"))
    };
}
// @ts-ignore TS6133
function flattenCfnGlobalTablePropsMixinReplicaSpecificationProperty(props) {
    if (cdk.isResolvableObject(props))
        return props;
    return {
        contributorInsightsSpecification: (!props.contributorInsightsSpecification ? undefined : props.contributorInsightsSpecification),
        deletionProtectionEnabled: (!props.deletionProtectionEnabled ? undefined : props.deletionProtectionEnabled),
        globalSecondaryIndexes: (!props.globalSecondaryIndexes ? undefined : props.globalSecondaryIndexes),
        globalTableSettingsReplicationMode: (!props.globalTableSettingsReplicationMode ? undefined : props.globalTableSettingsReplicationMode),
        kinesisStreamSpecification: (!props.kinesisStreamSpecification ? undefined : props.kinesisStreamSpecification),
        pointInTimeRecoverySpecification: (!props.pointInTimeRecoverySpecification ? undefined : props.pointInTimeRecoverySpecification),
        readOnDemandThroughputSettings: (!props.readOnDemandThroughputSettings ? undefined : props.readOnDemandThroughputSettings),
        readProvisionedThroughputSettings: (!props.readProvisionedThroughputSettings ? undefined : props.readProvisionedThroughputSettings),
        region: (!props.region ? undefined : props.region),
        replicaStreamSpecification: (!props.replicaStreamSpecification ? undefined : props.replicaStreamSpecification),
        resourcePolicy: (!props.resourcePolicy ? undefined : props.resourcePolicy),
        sseSpecification: (!props.sseSpecification ? undefined : (!props.sseSpecification ? undefined : flattenCfnGlobalTablePropsMixinReplicaSSESpecificationProperty(props.sseSpecification))),
        tableClass: (!props.tableClass ? undefined : props.tableClass),
        tags: (!props.tags ? undefined : props.tags)
    };
}
// @ts-ignore TS6133
function flattenCfnGlobalTableMixinProps(props) {
    const ret = {};
    if ((props.replicas !== undefined))
        ret.replicas = (cdk.isResolvableObject(props.replicas) ? props.replicas : cdk.mapArrayInPlace(props.replicas, (item) => flattenCfnGlobalTablePropsMixinReplicaSpecificationProperty(item)));
    return ret;
}
/**
 * The `AWS::DynamoDB::Table` resource creates a DynamoDB table. For more information, see [CreateTable](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_CreateTable.html) in the *Amazon DynamoDB API Reference* .
 *
 * You should be aware of the following behaviors when working with DynamoDB tables:
 *
 * - AWS CloudFormation typically creates DynamoDB tables in parallel. However, if your template includes multiple DynamoDB tables with indexes, you must declare dependencies so that the tables are created sequentially. Amazon DynamoDB limits the number of tables with secondary indexes that are in the creating state. If you create multiple tables with indexes at the same time, DynamoDB returns an error and the stack operation fails. For an example, see [DynamoDB Table with a DependsOn Attribute](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html#aws-resource-dynamodb-table--examples--DynamoDB_Table_with_a_DependsOn_Attribute) .
 *
 * > Our guidance is to use the latest schema documented for your AWS CloudFormation templates. This schema supports the provisioning of all table settings below. When using this schema in your AWS CloudFormation templates, please ensure that your Identity and Access Management ( IAM ) policies are updated with appropriate permissions to allow for the authorization of these setting changes.
 *
 * @cloudformationResource AWS::DynamoDB::Table
 * @mixin true
 * @stability external
 * @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html
 */
class CfnTablePropsMixin extends cdk.Mixin {
    static [JSII_RTTI_SYMBOL_1] = { fqn: "@aws-cdk/cfn-property-mixins.aws_dynamodb.CfnTablePropsMixin", version: "2.258.1" };
    static CFN_PROPERTY_KEYS = ["attributeDefinitions", "billingMode", "contributorInsightsSpecification", "deletionProtectionEnabled", "globalSecondaryIndexes", "importSourceSpecification", "keySchema", "kinesisStreamSpecification", "localSecondaryIndexes", "onDemandThroughput", "pointInTimeRecoverySpecification", "provisionedThroughput", "resourcePolicy", "sseSpecification", "streamSpecification", "tableClass", "tableName", "tags", "timeToLiveSpecification", "warmThroughput"];
    props;
    strategy;
    /**
     * Create a mixin to apply properties to `AWS::DynamoDB::Table`.
     *
     * @param props L1 properties to apply
     * @param options Mixin options
     */
    constructor(props, options = {}) {
        super();
        try {
            jsiiDeprecationWarnings._aws_cdk_cfn_property_mixins_aws_dynamodb_CfnTableMixinProps(props);
            jsiiDeprecationWarnings._aws_cdk_cfn_property_mixins_CfnPropertyMixinOptions(options);
        }
        catch (error) {
            if (process.env.JSII_DEBUG !== "1" && error.name === "DeprecationError") {
                Error.captureStackTrace(error, CfnTablePropsMixin);
            }
            throw error;
        }
        this.props = {
            ...props,
            ...flattenCfnTableMixinProps(props)
        };
        this.strategy = (options.strategy ?? cdk.PropertyMergeStrategy.combine());
    }
    /**
     * Check if this mixin supports the given construct
     */
    supports(construct) {
        return (cdk.CfnResource.isCfnResource(construct) && service.CfnTable.isCfnTable(construct));
    }
    /**
     * Apply the mixin properties to the construct
     */
    applyTo(construct) {
        if (this.supports(construct)) {
            this.strategy.apply(construct, this.props, CfnTablePropsMixin.CFN_PROPERTY_KEYS);
        }
    }
}
exports.CfnTablePropsMixin = CfnTablePropsMixin;
// @ts-ignore TS6133
function flattenCfnTablePropsMixinSSESpecificationProperty(props) {
    if (cdk.isResolvableObject(props))
        return props;
    return {
        kmsMasterKeyId: (!props.kmsMasterKeyId ? undefined : cdk.getRefProperty(props.kmsMasterKeyId?.keyRef, 'keyArn') ?? cdk.getRefProperty(props.kmsMasterKeyId?.keyRef, 'keyId') ?? cdk.getRefProperty(props.kmsMasterKeyId?.aliasRef, 'aliasName') ?? cdk.ensureStringOrUndefined(props.kmsMasterKeyId, "kmsMasterKeyId", "kms.IKeyRef | kms.IAliasRef | string")),
        sseEnabled: (!props.sseEnabled ? undefined : props.sseEnabled),
        sseType: (!props.sseType ? undefined : props.sseType)
    };
}
// @ts-ignore TS6133
function flattenCfnTablePropsMixinKinesisStreamSpecificationProperty(props) {
    if (cdk.isResolvableObject(props))
        return props;
    return {
        approximateCreationDateTimePrecision: (!props.approximateCreationDateTimePrecision ? undefined : props.approximateCreationDateTimePrecision),
        streamArn: (!props.streamArn ? undefined : cdk.getRefProperty(props.streamArn?.streamRef, 'streamArn') ?? cdk.ensureStringOrUndefined(props.streamArn, "streamArn", "kinesis.IStreamRef | string"))
    };
}
// @ts-ignore TS6133
function flattenCfnTableMixinProps(props) {
    const ret = {};
    if ((props.kinesisStreamSpecification !== undefined))
        ret.kinesisStreamSpecification = flattenCfnTablePropsMixinKinesisStreamSpecificationProperty(props.kinesisStreamSpecification);
    if ((props.sseSpecification !== undefined))
        ret.sseSpecification = flattenCfnTablePropsMixinSSESpecificationProperty(props.sseSpecification);
    return ret;
}
