{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Description": "(SO0166) - Virtual Waiting Room on AWS Getting Started v1.1.15",
    "Resources": {
        "CoreModuleStack": {
            "Type": "AWS::CloudFormation::Stack",
            "Properties": {
                "TemplateURL": {"Fn::Sub": "https://solutions-${AWS::Region}.s3.amazonaws.com/virtual-waiting-room-on-aws/v1.1.15/virtual-waiting-room-on-aws.template"},
                "Parameters": {
                    "EventId": {"Ref": "EventId"},
                    "ValidityPeriod": {"Ref": "ValidityPeriod"},
                    "EnableEventsGeneration": {"Ref": "EnableEventsGeneration"},
                    "RedisPort": {"Ref": "RedisPort"},
                    "QueuePositionExpiryPeriod":  {
                        "Ref": "QueuePositionExpiryPeriod"
                    },
                    "EnableQueuePositionExpiry": {
                        "Ref": "EnableQueuePositionExpiry"
                    },
                    "IncrSvcOnQueuePositionExpiry": {
                        "Ref": "IncrSvcOnQueuePositionExpiry"
                    }                
                }
            }
        },
        "AuthorizersModuleStack": {
            "Type": "AWS::CloudFormation::Stack",
            "Properties": {
                "TemplateURL": {"Fn::Sub": "https://solutions-${AWS::Region}.s3.amazonaws.com/virtual-waiting-room-on-aws/v1.1.15/virtual-waiting-room-on-aws-authorizers.template"},
                "Parameters": {
                    "PublicAPIEndpoint": {
                        "Fn::GetAtt": [
                            "CoreModuleStack",
                            "Outputs.PublicApiInvokeURL"
                        ]
                      },
                      "WaitingRoomEventID": {"Ref": "EventId"},
                      "IssuerURI": {
                        "Fn::GetAtt": [
                            "CoreModuleStack",
                            "Outputs.PublicTokenIssuer"
                        ]
                      }
                }
            }
        },
        "SampleModuleStack": {
            "Type": "AWS::CloudFormation::Stack",
            "Properties": {
                "TemplateURL": {"Fn::Sub": "https://solutions-${AWS::Region}.s3.amazonaws.com/virtual-waiting-room-on-aws/v1.1.15/virtual-waiting-room-on-aws-sample.template"},
                "Parameters": {
                    "AuthorizerARN": {
                        "Fn::GetAtt": [
                            "AuthorizersModuleStack",
                            "Outputs.ApiGatewayAuthorizerArn"
                        ]
                      },
                      "APIGatewayRegion": {"Fn::Sub": "${AWS::Region}"},
                      "PublicAPIEndpoint": {
                        "Fn::GetAtt": [
                            "CoreModuleStack",
                            "Outputs.PublicApiInvokeURL"
                        ]
                      },
                      "PrivateAPIEndpoint": {
                        "Fn::GetAtt": [
                            "CoreModuleStack",
                            "Outputs.PrivateApiInvokeURL"
                        ]
                      },
                      "EventID": {"Ref": "EventId"}
                }
            }
        }
    },
    "Parameters": {
        "EventId": {
            "Description": "Unique ID for this instance of the waiting room",
            "Type": "String",
            "MinLength": 1,
            "ConstraintDescription": "Please enter a value for this field.",
            "Default": "Sample"
        },
        "ValidityPeriod": {
            "Description": "Token validity period in seconds",
            "Type": "Number",
            "ConstraintDescription": "Please enter a value for this field.",
            "Default": 3600
        },
        "EnableEventsGeneration": {
            "Description": "If set to true, metrics related to the Waiting Room will be written to its event bus every minute",
            "Type": "String",
            "AllowedValues": [
                "true",
                "false"
            ],
            "Default": "false"
        },
        "RedisPort": {
            "Description": "Port to use when connecting to Redis",
            "Type": "Number",
            "ConstraintDescription": "Please enter a value for this field.",
            "Default": "1785"
        },
        "QueuePositionExpiryPeriod": {
            "Description": "Time interval beyond which a queue position is ineligible to generate a token (seconds)",
            "Type": "Number",
            "ConstraintDescription": "Please enter a value for this field.",
            "Default": "900"
        },
        "EnableQueuePositionExpiry": {
            "Description": "If set to false, expiry period is not applied to queue position",
            "Type": "String",
            "AllowedValues": [
                "true",
                "false"
            ],
            "Default": "true"
        },
        "IncrSvcOnQueuePositionExpiry": {
            "Description": "If set to true, serving counter is automatically advanced based on expired queue positions",
            "Type": "String",
            "AllowedValues": [
                "true",
                "false"
            ],
            "Default": "false"
        }
    },
    "Outputs": {
        "PublicApiInvokeURL": {
            "Value": {
                "Fn::GetAtt": [
                    "CoreModuleStack",
                    "Outputs.PublicApiInvokeURL"
                ]
            }
        },
        "PrivateApiInvokeURL": {
            "Value": {
                "Fn::GetAtt": [
                    "CoreModuleStack",
                    "Outputs.PrivateApiInvokeURL"
                ]
            }
        },
        "WaitingRoomURL": {
            "Value": {
                "Fn::GetAtt": [
                    "SampleModuleStack",
                    "Outputs.WaitingRoomURL"
                ]
            }
        },
        "ControlPanelURL": {
            "Value": {
                "Fn::GetAtt": [
                    "SampleModuleStack",
                    "Outputs.ControlPanelURL"
                ]
            }
        }
    }
}
