AWSTemplateFormatVersion: '2010-09-09'
Conditions:
  IsProd:
    Fn::Equals:
      - Ref: StageName
      - production
Globals:
  Function:
    Environment:
      Variables:
        TABLE_CASE_INSTANCE:
          Ref: TableCaseInstance
        TABLE_CASE_SUMMARY:
          Ref: TableCaseSummary
        TABLE_FILE_TIMING:
          Ref: TableFileTiming
    Handler: index.handler
    MemorySize: 256
    Runtime: nodejs18.x
    Timeout: 30
    Tracing: Active
Outputs:
  TableCaseInstance:
    Description: The name of the DynamoDB table for TableCaseInstance
    Export:
      Name:
        Fn::Sub: ${AWS::StackName}-TableCaseInstance
    Value:
      Ref: TableCaseInstance
  TableCaseSummary:
    Description: The name of the DynamoDB table for TableCaseSummary
    Export:
      Name:
        Fn::Sub: ${AWS::StackName}-TableCaseSummary
    Value:
      Ref: TableCaseSummary
  TableFileTiming:
    Description: The name of the DynamoDB table for TableFileTiming
    Export:
      Name:
        Fn::Sub: ${AWS::StackName}-TableFileTiming
    Value:
      Ref: TableFileTiming
Parameters:
  StageName:
    AllowedValues:
      - development
      - production
      - test
    Default: development
    Description: The name of the stage
    Type: String
Resources:
  TableCaseInstance:
    Properties:
      AttributeDefinitions:
        - AttributeName: pk
          AttributeType: S
        - AttributeName: sk
          AttributeType: S
        - AttributeName: gsi1pk
          AttributeType: S
        - AttributeName: gsi1sk
          AttributeType: S
        - AttributeName: gsi2pk
          AttributeType: S
        - AttributeName: gsi2sk
          AttributeType: S
        - AttributeName: lsi1sk
          AttributeType: S
        - AttributeName: lsi2sk
          AttributeType: S
      BillingMode: PAY_PER_REQUEST
      GlobalSecondaryIndexes:
        - IndexName: gsi1
          KeySchema:
            - AttributeName: gsi1pk
              KeyType: HASH
            - AttributeName: gsi1sk
              KeyType: RANGE
          Projection:
            ProjectionType: ALL
        - IndexName: gsi2
          KeySchema:
            - AttributeName: gsi2pk
              KeyType: HASH
            - AttributeName: gsi2sk
              KeyType: RANGE
          Projection:
            ProjectionType: ALL
      KeySchema:
        - AttributeName: pk
          KeyType: HASH
        - AttributeName: sk
          KeyType: RANGE
      LocalSecondaryIndexes:
        - IndexName: lsi1
          KeySchema:
            - AttributeName: pk
              KeyType: HASH
            - AttributeName: lsi1sk
              KeyType: RANGE
          Projection:
            ProjectionType: ALL
        - IndexName: lsi2
          KeySchema:
            - AttributeName: pk
              KeyType: HASH
            - AttributeName: lsi2sk
              KeyType: RANGE
          Projection:
            ProjectionType: ALL
      PointInTimeRecoverySpecification:
        PointInTimeRecoveryEnabled:
          Fn::If:
            - IsProd
            - true
            - false
      SSESpecification:
        SSEEnabled:
          Fn::If:
            - IsProd
            - true
            - false
      Tags:
        - Key: StageName
          Value:
            Ref: StageName
        - Key: TableName
          Value: TableCaseInstance
    Type: AWS::DynamoDB::Table
  TableCaseSummary:
    Properties:
      AttributeDefinitions:
        - AttributeName: pk
          AttributeType: S
        - AttributeName: sk
          AttributeType: S
        - AttributeName: lsi1sk
          AttributeType: S
        - AttributeName: lsi2sk
          AttributeType: S
      BillingMode: PAY_PER_REQUEST
      KeySchema:
        - AttributeName: pk
          KeyType: HASH
        - AttributeName: sk
          KeyType: RANGE
      LocalSecondaryIndexes:
        - IndexName: lsi1
          KeySchema:
            - AttributeName: pk
              KeyType: HASH
            - AttributeName: lsi1sk
              KeyType: RANGE
          Projection:
            ProjectionType: ALL
        - IndexName: lsi2
          KeySchema:
            - AttributeName: pk
              KeyType: HASH
            - AttributeName: lsi2sk
              KeyType: RANGE
          Projection:
            ProjectionType: ALL
      PointInTimeRecoverySpecification:
        PointInTimeRecoveryEnabled:
          Fn::If:
            - IsProd
            - true
            - false
      SSESpecification:
        SSEEnabled:
          Fn::If:
            - IsProd
            - true
            - false
      Tags:
        - Key: StageName
          Value:
            Ref: StageName
        - Key: TableName
          Value: TableCaseSummary
    Type: AWS::DynamoDB::Table
  TableFileTiming:
    Properties:
      AttributeDefinitions:
        - AttributeName: pk
          AttributeType: S
        - AttributeName: sk
          AttributeType: S
        - AttributeName: gsi2pk
          AttributeType: S
        - AttributeName: gsi2sk
          AttributeType: S
        - AttributeName: lsi1sk
          AttributeType: S
      BillingMode: PAY_PER_REQUEST
      GlobalSecondaryIndexes:
        - IndexName: gsi2
          KeySchema:
            - AttributeName: gsi2pk
              KeyType: HASH
            - AttributeName: gsi2sk
              KeyType: RANGE
          Projection:
            ProjectionType: ALL
      KeySchema:
        - AttributeName: pk
          KeyType: HASH
        - AttributeName: sk
          KeyType: RANGE
      LocalSecondaryIndexes:
        - IndexName: lsi1
          KeySchema:
            - AttributeName: pk
              KeyType: HASH
            - AttributeName: lsi1sk
              KeyType: RANGE
          Projection:
            ProjectionType: ALL
      PointInTimeRecoverySpecification:
        PointInTimeRecoveryEnabled:
          Fn::If:
            - IsProd
            - true
            - false
      SSESpecification:
        SSEEnabled:
          Fn::If:
            - IsProd
            - true
            - false
      Tags:
        - Key: StageName
          Value:
            Ref: StageName
        - Key: TableName
          Value: TableFileTiming
    Type: AWS::DynamoDB::Table
Transform: AWS::Serverless-2016-10-31
