AWSTemplateFormatVersion: "2010-09-09"
Description: "Configure a StatelyDB BYOC DynamoDB table"

Parameters:
  TableName:
    Type: String
    Description: Name of the DynamoDB table
    MinLength: 1

Resources:
  StatelyTable:
    Type: AWS::DynamoDB::Table
    Properties:
      TableName: !Ref TableName
      BillingMode: PAY_PER_REQUEST
      DeletionProtectionEnabled: true
      AttributeDefinitions:
        - AttributeName: A
          AttributeType: B
        - AttributeName: B
          AttributeType: B
        - AttributeName: D
          AttributeType: B
        - AttributeName: F
          AttributeType: B
        - AttributeName: G
          AttributeType: B
        - AttributeName: H
          AttributeType: B
        - AttributeName: I
          AttributeType: B
      KeySchema:
        - AttributeName: A
          KeyType: HASH
        - AttributeName: B
          KeyType: RANGE
      LocalSecondaryIndexes:
        - IndexName: LSI0
          KeySchema:
            - AttributeName: A
              KeyType: HASH
            - AttributeName: D
              KeyType: RANGE
          Projection:
            ProjectionType: ALL
        - IndexName: LSI1
          KeySchema:
            - AttributeName: A
              KeyType: HASH
            - AttributeName: F
              KeyType: RANGE
          Projection:
            ProjectionType: ALL
        - IndexName: LSI2
          KeySchema:
            - AttributeName: A
              KeyType: HASH
            - AttributeName: G
              KeyType: RANGE
          Projection:
            ProjectionType: ALL
        - IndexName: LSI3
          KeySchema:
            - AttributeName: A
              KeyType: HASH
            - AttributeName: H
              KeyType: RANGE
          Projection:
            ProjectionType: ALL
        - IndexName: LSI4
          KeySchema:
            - AttributeName: A
              KeyType: HASH
            - AttributeName: I
              KeyType: RANGE
          Projection:
            ProjectionType: ALL
      TimeToLiveSpecification:
        AttributeName: E
        Enabled: true
      PointInTimeRecoverySpecification:
        PointInTimeRecoveryEnabled: true

Outputs:
  TableArn:
    Description: ARN of the created DynamoDB table
    Value: !GetAtt StatelyTable.Arn
