{
    "Comment": "Trigger a scheduled product metadata update",
    "StartAt": "ValidateProduct",
    "States": {
      "ValidateProduct": {
        "Type": "Task",
        "Resource": "${lambda_ws_validate_product_arn}",
        "ResultPath": "$.validateProductResult",
        "Next": "CheckValidationResult",
        "Retry": [
          {
            "ErrorEquals": [ "ValidateProductFailed" ],
            "IntervalSeconds": 5,
            "MaxAttempts": 3,
            "BackoffRate": 3
          },
          {
            "ErrorEquals": [
              "States.Timeout",
              "Lambda.ServiceException",
              "Lambda.AWSLambdaException",
              "Lambda.SdkClientException",
              "Lambda.TooManyRequestsException"
            ],
            "IntervalSeconds": 5,
            "MaxAttempts": 5,
            "BackoffRate": 3
          }
        ],
        "Catch": [
          {
            "ErrorEquals": [ "States.ALL" ],
            "ResultPath": "$.error",
            "Next": "SendEmailNotification"
          } 
        ]
      },
      "CheckValidationResult": {
        "Type": "Choice",
        "Choices": [
          {
            "Variable": "$.validateProductResult.status",
            "StringEquals": "FAILED",
            "Next": "SendEmailNotification"
          }
        ],
        "Default": "FetchDSPIds"
      },
      "FetchDSPIds": {
        "Type": "Task",
        "Resource": "${lambda_ws_fetch_dsp_ids_arn}",
        "ResultPath": "$.fetchDSPIdsResult",
        "Next": "UpdateMetadataQueue",
        "Retry": [
          {
            "ErrorEquals": [ "FetchDSPIdsFailed" ],
            "IntervalSeconds": 5,
            "MaxAttempts": 3,
            "BackoffRate": 3
          },
          {
            "ErrorEquals": [
              "States.Timeout",
              "Lambda.ServiceException",
              "Lambda.AWSLambdaException",
              "Lambda.SdkClientException",
              "Lambda.TooManyRequestsException"
            ],
            "IntervalSeconds": 5,
            "MaxAttempts": 5,
            "BackoffRate": 3
          }
        ],
        "Catch": [
          {
            "ErrorEquals": [ "States.ALL" ],
            "ResultPath": "$.error",
            "Next": "SendEmailNotification"
          }
        ]
      },
      "UpdateMetadataQueue": {
        "Type": "Task",
        "Resource": "${lambda_update_metadata_queue_arn}",
        "ResultPath": "$.updateMetadataQueueResult",
        "Parameters": {
          "productId.$": "$.productId",
          "deliveryStoreIds.$": "$.fetchDSPIdsResult.deliveryStoreIds"
        },
        "Next": "SendEmailNotification",
        "Retry": [
          {
            "ErrorEquals": [ "UpdateMetadataQueueFailed" ],
            "IntervalSeconds": 5,
            "MaxAttempts": 3,
            "BackoffRate": 3
          },
          {
            "ErrorEquals": [
              "States.Timeout",
              "Lambda.ServiceException",
              "Lambda.AWSLambdaException",
              "Lambda.SdkClientException",
              "Lambda.TooManyRequestsException"
            ],
            "IntervalSeconds": 5,
            "MaxAttempts": 5,
            "BackoffRate": 3
          }
        ],
        "Catch": [
          {
            "ErrorEquals": [ "States.ALL" ],
            "ResultPath": "$.error",
            "Next": "SendEmailNotification"
          }
        ]
      },
      "SendEmailNotification": {
        "Type": "Task",
        "Resource": "${lambda_ws_send_notification_arn}",
        "ResultPath": "$.SendEmailNotificationResult",
        "Next": "HandleError",
        "Retry": [
          {
            "ErrorEquals": [
              "States.Timeout",
              "Lambda.ServiceException",
              "Lambda.AWSLambdaException",
              "Lambda.SdkClientException",
              "Lambda.TooManyRequestsException"
            ],
            "IntervalSeconds": 5,
            "MaxAttempts": 5,
            "BackoffRate": 3
          }
        ],
        "Catch": [ 
          {
            "ErrorEquals": [ "States.ALL" ],
            "ResultPath": "$.error",
            "Next": "FailState"
          }
        ]
      },
      "HandleError": {
        "Type": "Choice",
        "Choices": [
          {
            "Variable": "$.error",
            "IsPresent": false,
            "Next": "SuccessState"
          },
          {
            "Variable": "$.error",
            "IsPresent": true,
            "Next": "FailState"
          }
        ]
      },
      "SuccessState": {
        "Type": "Succeed"
      },
      "FailState": {
        "Type": "Fail",
        "ErrorPath": "$.error.Error",
        "CausePath": "$.error.Cause"
      }
    }
  }
