{
  "Comment": "Handles parsing an AWAL DDEX document and ingesting information from it into the Orchard",
  "StartAt": "CheckForSentinelFile",
  "States": {
    "CheckForSentinelFile": {
      "Type": "Choice",
      "Choices": [
        {
          "Variable": "$.detail.requestParameters.key",
          "StringMatches": "*/${filename_pattern}",
          "Next": "ParseDDEX"
        }
      ],
      "Default": "FailState"
    },
    "ParseDDEX": {
      "Type": "Task",
      "Resource": "${lambda_parse_ddex_arn}",
      "Parameters": {
        "bucket.$": "$.detail.requestParameters.bucketName",
        "key.$": "$.detail.requestParameters.key",
        "ingest_id.$": "$.detail.requestParameters.ingest_id",
        "ddex_provider.$": "$.detail.requestParameters.ddex_provider",
        "execution_name.$": "$$.Execution.Name",
        "state_machine_name.$": "$$.StateMachine.Name",
        "execution_start_time.$": "$$.Execution.StartTime"
      },
      "Retry": [
        {
          "ErrorEquals": [
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 5,
          "BackoffRate": 3
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "FailState",
          "ResultPath": "$.errors"
        }
      ],
      "Next": "CheckPurgedRelease"
    },
    "CheckPurgedRelease": {
      "Type": "Choice",
      "Choices": [
        {
          "Variable": "$.is_purged_release",
          "BooleanEquals": true,
          "Next": "HandlePurgedRelease"
        }
      ],
      "Default": "PrepDDEX"
    },
    "HandlePurgedRelease": {
      "Type": "Task",
      "Resource": "${lambda_handle_purged_release_arn}",
      "HeartbeatSeconds": 60,
      "TimeoutSeconds": 3600,
      "Retry": [
        {
          "ErrorEquals": [
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 5,
          "BackoffRate": 3
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "WriteCatalogIngestionFailure",
          "ResultPath": "$.errors"
        }
      ],
      "Next": "WriteCatalogIngestionSuccess"
    },
    "PrepDDEX": {
      "Type": "Task",
      "Resource": "${lambda_prep_ddex_arn}",
      "HeartbeatSeconds": 60,
      "TimeoutSeconds": 3600,
      "Retry": [
        {
          "ErrorEquals": [
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 5,
          "BackoffRate": 3
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "WriteCatalogIngestionFailure",
          "ResultPath": "$.errors"
        }
      ],
      "Next": "ValidateDDEX"
    },
    "ValidateDDEX": {
      "Type": "Task",
      "Resource": "${lambda_validate_ddex_arn}",
      "HeartbeatSeconds": 60,
      "TimeoutSeconds": 3600,
      "Retry": [
        {
          "ErrorEquals": [
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 5,
          "BackoffRate": 3
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "WriteCatalogIngestionFailure",
          "ResultPath": "$.errors"
        }
      ],
      "Next": "ProcessParticipants"
    },
    "ProcessParticipants": {
      "Type": "Task",
      "Resource": "${lambda_process_participants_arn}",
      "HeartbeatSeconds": 60,
      "TimeoutSeconds": 3600,
      "Retry": [
        {
          "ErrorEquals": [
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 5,
          "BackoffRate": 3
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "WriteCatalogIngestionFailure",
          "ResultPath": "$.errors"
        }
      ],
      "Next": "SetProject"
    },
    "SetProject": {
      "Type": "Task",
      "Resource": "${lambda_set_project_arn}",
      "HeartbeatSeconds": 60,
      "TimeoutSeconds": 3600,
      "Retry": [
        {
          "ErrorEquals": [
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 5,
          "BackoffRate": 3
        },
        {
          "ErrorEquals": [
            "DuplicateProjectCodeException"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 3,
          "BackoffRate": 3
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "WriteCatalogIngestionFailure",
          "ResultPath": "$.errors"
        }
      ],
      "Next": "CheckVideoRelease"
    },
    "CheckVideoRelease": {
      "Type": "Choice",
      "Choices": [
        {
          "Variable": "$.product.release_type",
          "StringMatches": "VideoSingle",
          "Next": "CreateVideo"
        }
      ],
      "Default": "SetProduct"
    },
    "SetProduct": {
      "Type": "Task",
      "Resource": "${lambda_set_product_arn}",
      "HeartbeatSeconds": 60,
      "TimeoutSeconds": 3600,
      "Retry": [
        {
          "ErrorEquals": [
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 5,
          "BackoffRate": 3
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "WriteCatalogIngestionFailure",
          "ResultPath": "$.errors"
        }
      ],
      "Next": "GetOrchardProductMetadata"
    },
    "CreateVideo": {
      "Type": "Task",
      "Resource": "${lambda_create_video_arn}",
      "HeartbeatSeconds": 60,
      "TimeoutSeconds": 3600,
      "Retry": [
        {
          "ErrorEquals": [
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 5,
          "BackoffRate": 3
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "WriteCatalogIngestionFailure",
          "ResultPath": "$.errors"
        }
      ],
      "Next": "LookupVideoProduct"
    },
    "LookupVideoProduct": {
      "Type": "Task",
      "Resource": "${lambda_lookup_video_product_arn}",
      "HeartbeatSeconds": 60,
      "TimeoutSeconds": 3600,
      "Retry": [
        {
          "ErrorEquals": [
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 5,
          "BackoffRate": 3
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "WriteCatalogIngestionFailure",
          "ResultPath": "$.errors"
        }
      ],
      "Next": "ProcessVideoProduct"
    },
    "ProcessVideoProduct": {
      "Type": "Parallel",
      "Branches": [
        {
          "StartAt": "ProcessVideos",
          "States": {
            "ProcessVideos": {
              "Type": "Map",
              "MaxConcurrency": 20,
              "ItemsPath": "$.video.assets",
              "Parameters": {
                "context.$": "$",
                "asset.$": "$$.Map.Item.Value"
              },
              "Iterator": {
                "StartAt": "ProcessVideoAssets",
                "States": {
                  "ProcessVideoAssets": {
                    "Type": "Parallel",
                    "Branches": [
                      {
                        "StartAt": "VideoAssetFound",
                        "States": {
                          "VideoAssetFound": {
                            "Type": "Choice",
                            "Choices": [
                              {
                                "Variable": "$.asset",
                                "IsNull": false,
                                "Next": "HandleVideoAsset"
                              }
                            ],
                            "Default": "MissingVideoAsset"
                          },
                          "HandleVideoAsset": {
                            "Type": "Task",
                            "Resource": "${lambda_handle_video_asset_arn}",
                            "HeartbeatSeconds": 60,
                            "TimeoutSeconds": 3600,
                            "Catch": [
                              {
                                "ErrorEquals": [
                                  "States.ALL"
                                ],
                                "Next": "CatchHandleVideoAssetError",
                                "ResultPath": "$.errors"
                              }
                            ],
                            "Retry": [
                              {
                                "ErrorEquals": [
                                  "States.Timeout",
                                  "Lambda.ServiceException",
                                  "Lambda.AWSLambdaException",
                                  "Lambda.SdkClientException",
                                  "Lambda.TooManyRequestsException"
                                ],
                                "IntervalSeconds": 5,
                                "MaxAttempts": 5,
                                "BackoffRate": 3
                              }
                            ],
                            "Next": "PollVideoAssetStatus"
                          },
                          "PollVideoAssetStatus": {
                            "Type": "Task",
                            "Resource": "${lambda_poll_video_asset_status_arn}",
                            "HeartbeatSeconds": 60,
                            "TimeoutSeconds": 3600,
                            "Catch": [
                              {
                                "ErrorEquals": [
                                  "TriggerVideoResolutionFixException"
                                ],
                                "Next": "FixVideoResolution",
                                "ResultPath": "$.errors"
                              },
                              {
                                "ErrorEquals": [
                                  "States.ALL"
                                ],
                                "Next": "CatchHandleVideoAssetError",
                                "ResultPath": "$.errors"
                              }
                            ],
                            "Retry": [
                              {
                                "ErrorEquals": [
                                  "VideoException"
                                ],
                                "IntervalSeconds": 60,
                                "MaxAttempts": 120,
                                "BackoffRate": 1
                              },
                              {
                                "ErrorEquals": [
                                  "States.Timeout",
                                  "Lambda.ServiceException",
                                  "Lambda.AWSLambdaException",
                                  "Lambda.SdkClientException",
                                  "Lambda.TooManyRequestsException"
                                ],
                                "IntervalSeconds": 5,
                                "MaxAttempts": 5,
                                "BackoffRate": 3
                              }
                            ],
                            "End": true
                          },
                          "FixVideoResolution": {
                            "Type": "Task",
                            "Resource": "${lambda_fix_video_resolution_arn}",
                            "Retry": [
                              {
                                "ErrorEquals": [
                                  "States.Timeout",
                                  "Lambda.ServiceException",
                                  "Lambda.AWSLambdaException",
                                  "Lambda.SdkClientException",
                                  "Lambda.TooManyRequestsException"
                                ],
                                "IntervalSeconds": 5,
                                "MaxAttempts": 3,
                                "BackoffRate": 3
                              }
                            ],
                            "Catch": [
                              {
                                "ErrorEquals": [
                                  "States.ALL"
                                ],
                                "Next": "CatchHandleVideoAssetError",
                                "ResultPath": "$.errors"
                              }
                            ],
                            "Next": "CatchHandleVideoAssetError"
                          },
                          "CatchHandleVideoAssetError": {
                            "Type": "Succeed"
                          },
                          "MissingVideoAsset": {
                            "Type": "Succeed"
                          }
                        }
                      }
                    ],
                    "End": true
                  }
                }
              },
              "End": true
            }
          }
        },
        {
          "StartAt": "ProcessVideoCarveouts",
          "States": {
            "ProcessVideoCarveouts": {
              "Type": "Task",
              "Resource": "${lambda_set_carveouts_arn}",
              "HeartbeatSeconds": 60,
              "TimeoutSeconds": 3600,
              "Retry": [
                {
                  "ErrorEquals": [
                    "States.Timeout",
                    "Lambda.ServiceException",
                    "Lambda.AWSLambdaException",
                    "Lambda.SdkClientException",
                    "Lambda.TooManyRequestsException"
                  ],
                  "IntervalSeconds": 5,
                  "MaxAttempts": 5,
                  "BackoffRate": 3
                }
              ],
              "Catch": [
                {
                  "ErrorEquals": [
                    "States.ALL"
                  ],
                  "Next": "CatchVideoCarveoutErrors",
                  "ResultPath": "$.errors"
                }
              ],
              "End": true
            },
            "CatchVideoCarveoutErrors": {
              "Type": "Succeed"
            }
          }
        },
        {
          "StartAt": "ProcessVideoPricing",
          "States": {
            "ProcessVideoPricing": {
              "Type": "Task",
              "Resource": "${lambda_set_pricing_arn}",
              "HeartbeatSeconds": 60,
              "TimeoutSeconds": 3600,
              "Retry": [
                {
                  "ErrorEquals": [
                    "States.Timeout",
                    "Lambda.ServiceException",
                    "Lambda.AWSLambdaException",
                    "Lambda.SdkClientException",
                    "Lambda.TooManyRequestsException"
                  ],
                  "IntervalSeconds": 5,
                  "MaxAttempts": 5,
                  "BackoffRate": 3
                }
              ],
              "Catch": [
                {
                  "ErrorEquals": [
                    "States.ALL"
                  ],
                  "ResultPath": "$.errors",
                  "Next": "CatchVideoPricingErrors"
                }
              ],
              "End": true
            },
            "CatchVideoPricingErrors": {
              "Type": "Succeed"
            }
          }
        },
        {
          "StartAt": "SetVideoReleaseDate",
          "States": {
            "SetVideoReleaseDate": {
              "Type": "Task",
              "Resource": "${lambda_set_main_release_date_arn}",
              "HeartbeatSeconds": 60,
              "TimeoutSeconds": 3600,
              "Retry": [
                {
                  "ErrorEquals": [
                    "States.Timeout",
                    "Lambda.ServiceException",
                    "Lambda.AWSLambdaException",
                    "Lambda.SdkClientException",
                    "Lambda.TooManyRequestsException"
                  ],
                  "IntervalSeconds": 5,
                  "MaxAttempts": 5,
                  "BackoffRate": 3
                }
              ],
              "Catch": [
                {
                  "ErrorEquals": [
                    "States.ALL"
                  ],
                  "Next": "CatchVideoReleaseDateErrors",
                  "ResultPath": "$.errors"
                }
              ],
              "End": true
            },
            "CatchVideoReleaseDateErrors": {
              "Type": "Succeed"
            }
          }
        },
        {
          "StartAt": "SetVideoMetadata",
          "States": {
            "SetVideoMetadata": {
              "Type": "Task",
              "Resource": "${lambda_set_video_metadata_arn}",
              "HeartbeatSeconds": 60,
              "TimeoutSeconds": 3600,
              "Retry": [
                {
                  "ErrorEquals": [
                    "States.Timeout",
                    "Lambda.ServiceException",
                    "Lambda.AWSLambdaException",
                    "Lambda.SdkClientException",
                    "Lambda.TooManyRequestsException"
                  ],
                  "IntervalSeconds": 5,
                  "MaxAttempts": 5,
                  "BackoffRate": 3
                }
              ],
              "Catch": [
                {
                  "ErrorEquals": [
                    "States.ALL"
                  ],
                  "Next": "CatchVideoMetadataErrors",
                  "ResultPath": "$.errors"
                }
              ],
              "End": true
            },
            "CatchVideoMetadataErrors": {
              "Type": "Succeed"
            }
          }
        }
      ],
      "Next": "DetectErrors"
    },
    "GetOrchardProductMetadata": {
      "Type": "Task",
      "Resource": "${lambda_retrieve_orchard_metadata_arn}",
      "HeartbeatSeconds": 60,
      "TimeoutSeconds": 3600,
      "Retry": [
        {
          "ErrorEquals": [
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 5,
          "BackoffRate": 3
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "WriteCatalogIngestionFailure",
          "ResultPath": "$.errors"
        }
      ],
      "Next": "CreateTracks"
    },
    "CreateTracks": {
      "Type": "Task",
      "Resource": "${lambda_create_tracks_arn}",
      "HeartbeatSeconds": 60,
      "TimeoutSeconds": 3600,
      "Retry": [
        {
          "ErrorEquals": [
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 5,
          "BackoffRate": 3
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "WriteCatalogIngestionFailure",
          "ResultPath": "$.errors"
        }
      ],
      "Next": "ProcessProductData"
    },
    "ProcessProductData": {
      "Type": "Parallel",
      "Branches": [
        {
          "StartAt": "ProcessTrackAssets",
          "States": {
            "ProcessTrackAssets": {
              "Type": "Map",
              "MaxConcurrency": 12,
              "ItemsPath": "$.tracks",
              "Parameters": {
                "track.$": "$$.Map.Item.Value",
                "context": {
                  "product.$": "$.product",
                  "error_correction.$": "$.error_correction",
                  "is_purged_release.$": "$.is_purged_release",
                  "bucket.$": "$.bucket",
                  "key.$": "$.key",
                  "errors.$": "$.errors",
                  "message_id.$": "$.message_id",
                  "message_thread_id.$": "$.message_thread_id",
                  "update_indicator.$": "$.update_indicator",
                  "maintenance_owner.$": "$.maintenance_owner",
                  "orchard_label.$": "$.orchard_label",
                  "execution_name.$": "$.execution_name",
                  "state_machine_name.$": "$.state_machine_name",
                  "execution_start_time.$": "$.execution_start_time",
                  "project_id.$": "$.project_id",
                  "warnings.$": "$.warnings",
                  "ddex_provider.$": "$.ddex_provider",
                  "correlation_id.$": "$.correlation_id",
                  "deal_coordinators.$": "$.deal_coordinators",
                  "has_switchboard_deal.$": "$.has_switchboard_deal"
                }
              },
              "Iterator": {
                "StartAt": "AssetFound",
                "States": {
                  "AssetFound": {
                    "Type": "Choice",
                    "Choices": [
                      {
                        "Variable": "$.track.asset",
                        "IsNull": false,
                        "Next": "HandleAudioAsset"
                      }
                    ],
                    "Default": "MissingAsset"
                  },
                  "HandleAudioAsset": {
                    "Type": "Task",
                    "Resource": "${lambda_handle_audio_asset_arn}",
                    "HeartbeatSeconds": 60,
                    "TimeoutSeconds": 3600,
                    "Catch": [
                      {
                        "ErrorEquals": [
                          "States.ALL"
                        ],
                        "Next": "CatchHandleAudioAssetError"
                      }
                    ],
                    "Retry": [
                      {
                        "ErrorEquals": [
                          "States.Timeout",
                          "Lambda.ServiceException",
                          "Lambda.AWSLambdaException",
                          "Lambda.SdkClientException",
                          "Lambda.TooManyRequestsException"
                        ],
                        "IntervalSeconds": 5,
                        "MaxAttempts": 5,
                        "BackoffRate": 3
                      }
                    ],
                    "Next": "PollAudioAssetStatus"
                  },
                  "PollAudioAssetStatus": {
                    "Type": "Task",
                    "Resource": "${lambda_poll_audio_asset_status_arn}",
                    "HeartbeatSeconds": 60,
                    "TimeoutSeconds": 3600,
                    "Catch": [
                      {
                        "ErrorEquals": [
                          "States.ALL"
                        ],
                        "Next": "CatchHandleAudioAssetError"
                      }
                    ],
                    "Retry": [
                      {
                        "ErrorEquals": [
                          "AudioException"
                        ],
                        "IntervalSeconds": 60,
                        "MaxAttempts": 120,
                        "BackoffRate": 1
                      },
                      {
                        "ErrorEquals": [
                          "States.Timeout",
                          "Lambda.ServiceException",
                          "Lambda.AWSLambdaException",
                          "Lambda.SdkClientException",
                          "Lambda.TooManyRequestsException"
                        ],
                        "IntervalSeconds": 5,
                        "MaxAttempts": 5,
                        "BackoffRate": 3
                      }
                    ],
                    "OutputPath": "$.errors",
                    "End": true
                  },
                  "CatchHandleAudioAssetError": {
                    "Type": "Succeed"
                  },
                  "MissingAsset": {
                    "Type": "Succeed",
                    "OutputPath": "$.context.errors"
                  }
                }
              },
              "End": true
            }
          }
        },
        {
          "StartAt": "ProcessTrackMetadata",
          "States": {
            "ProcessTrackMetadata": {
              "Type": "Map",
              "MaxConcurrency": 1,
              "ItemsPath": "$.tracks",
              "Parameters": {
                "track.$": "$$.Map.Item.Value",
                "context": {
                  "product.$": "$.product",
                  "error_correction.$": "$.error_correction",
                  "is_purged_release.$": "$.is_purged_release",
                  "bucket.$": "$.bucket",
                  "key.$": "$.key",
                  "errors.$": "$.errors",
                  "message_id.$": "$.message_id",
                  "message_thread_id.$": "$.message_thread_id",
                  "update_indicator.$": "$.update_indicator",
                  "maintenance_owner.$": "$.maintenance_owner",
                  "orchard_label.$": "$.orchard_label",
                  "execution_name.$": "$.execution_name",
                  "state_machine_name.$": "$.state_machine_name",
                  "execution_start_time.$": "$.execution_start_time",
                  "project_id.$": "$.project_id",
                  "warnings.$": "$.warnings",
                  "ddex_provider.$": "$.ddex_provider",
                  "correlation_id.$": "$.correlation_id",
                  "deal_coordinators.$": "$.deal_coordinators",
                  "has_switchboard_deal.$": "$.has_switchboard_deal"
                }
              },
              "Iterator": {
                "StartAt": "SetTrackMetadata",
                "States": {
                  "SetTrackMetadata": {
                    "Type": "Task",
                    "Resource": "${lambda_set_track_metadata_arn}",
                    "HeartbeatSeconds": 60,
                    "TimeoutSeconds": 3600,
                    "Catch": [
                      {
                        "ErrorEquals": [
                          "States.ALL"
                        ],
                        "Next": "CatchSetTrackMetadataError"
                      }
                    ],
                    "Retry": [
                      {
                        "ErrorEquals": [
                          "States.Timeout",
                          "Lambda.ServiceException",
                          "Lambda.AWSLambdaException",
                          "Lambda.SdkClientException",
                          "SetTrackMetadataException"
                        ],
                        "IntervalSeconds": 5,
                        "MaxAttempts": 5,
                        "BackoffRate": 3
                      },
                      {
                        "ErrorEquals": [
                          "OwsProductUserIsForbiddenException"
                        ],
                        "IntervalSeconds": 300,
                        "MaxAttempts": 7,
                        "BackoffRate": 2
                      },
                      {
                        "ErrorEquals": [
                          "Lambda.TooManyRequestsException"
                        ],
                        "IntervalSeconds": 10,
                        "MaxAttempts": 5,
                        "BackoffRate": 5
                      }
                    ],
                    "OutputPath": "$.errors",
                    "End": true
                  },
                  "CatchSetTrackMetadataError": {
                    "Type": "Succeed"
                  }
                }
              },
              "End": true
            }
          }
        },
        {
          "StartAt": "ProcessCarveouts",
          "States": {
            "ProcessCarveouts": {
              "Type": "Task",
              "Resource": "${lambda_set_carveouts_arn}",
              "HeartbeatSeconds": 60,
              "TimeoutSeconds": 3600,
              "Retry": [
                {
                  "ErrorEquals": [
                    "States.Timeout",
                    "Lambda.ServiceException",
                    "Lambda.AWSLambdaException",
                    "Lambda.SdkClientException",
                    "Lambda.TooManyRequestsException"
                  ],
                  "IntervalSeconds": 5,
                  "MaxAttempts": 5,
                  "BackoffRate": 3
                }
              ],
              "Catch": [
                {
                  "ErrorEquals": [
                    "States.ALL"
                  ],
                  "Next": "CatchCarveoutErrors"
                }
              ],
              "OutputPath": "$.errors",
              "End": true
            },
            "CatchCarveoutErrors": {
              "Type": "Succeed"
            }
          }
        },
        {
          "StartAt": "ArtworkFound",
          "States": {
            "ArtworkFound": {
              "Type": "Choice",
              "Choices": [
                {
                  "Variable": "$.product.artwork",
                  "IsNull": false,
                  "Next": "HandleArtwork"
                }
              ],
              "Default": "MissingArtwork"
            },
            "HandleArtwork": {
              "Type": "Task",
              "Resource": "${lambda_handle_artwork_arn}",
              "HeartbeatSeconds": 60,
              "TimeoutSeconds": 3600,
              "Retry": [
                {
                  "ErrorEquals": [
                    "States.Timeout",
                    "Lambda.ServiceException",
                    "Lambda.AWSLambdaException",
                    "Lambda.SdkClientException",
                    "Lambda.TooManyRequestsException"
                  ],
                  "IntervalSeconds": 5,
                  "MaxAttempts": 5,
                  "BackoffRate": 3
                }
              ],
              "Catch": [
                {
                  "ErrorEquals": [
                    "States.ALL"
                  ],
                  "Next": "CatchHandleArtworkErrors"
                }
              ],
              "Next": "PollArtworkAssetStatus"
            },
            "PollArtworkAssetStatus": {
              "Type": "Task",
              "Resource": "${lambda_poll_artwork_asset_status_arn}",
              "HeartbeatSeconds": 60,
              "TimeoutSeconds": 3600,
              "Retry": [
                {
                  "ErrorEquals": [
                    "ArtworkException"
                  ],
                  "IntervalSeconds": 60,
                  "MaxAttempts": 120,
                  "BackoffRate": 1
                },
                {
                  "ErrorEquals": [
                    "States.Timeout",
                    "Lambda.ServiceException",
                    "Lambda.AWSLambdaException",
                    "Lambda.SdkClientException",
                    "Lambda.TooManyRequestsException"
                  ],
                  "IntervalSeconds": 5,
                  "MaxAttempts": 5,
                  "BackoffRate": 3
                }
              ],
              "Catch": [
                {
                  "ErrorEquals": [
                    "States.ALL"
                  ],
                  "Next": "CatchHandleArtworkErrors"
                }
              ],
              "OutputPath": "$.errors",
              "End": true
            },
            "CatchHandleArtworkErrors": {
              "Type": "Succeed"
            },
            "MissingArtwork": {
              "Type": "Succeed",
              "OutputPath": "$.errors"
            }
          }
        },
        {
          "StartAt": "ProcessPricing",
          "States": {
            "ProcessPricing": {
              "Type": "Task",
              "Resource": "${lambda_set_pricing_arn}",
              "HeartbeatSeconds": 60,
              "TimeoutSeconds": 3600,
              "Retry": [
                {
                  "ErrorEquals": [
                    "States.Timeout",
                    "Lambda.ServiceException",
                    "Lambda.AWSLambdaException",
                    "Lambda.SdkClientException",
                    "Lambda.TooManyRequestsException"
                  ],
                  "IntervalSeconds": 5,
                  "MaxAttempts": 5,
                  "BackoffRate": 3
                }
              ],
              "Catch": [
                {
                  "ErrorEquals": [
                    "States.ALL"
                  ],
                  "Next": "CatchPricingErrors",
                  "ResultPath": "$.errors"
                }
              ],
              "End": true
            },
            "CatchPricingErrors": {
              "Type": "Succeed"
            }
          }
        },
        {
          "StartAt": "ImportDeliveryHistory",
          "States": {
            "ImportDeliveryHistory": {
              "Type": "Task",
              "Resource": "${lambda_import_delivery_history_from_ext_ddex_arn}",
              "HeartbeatSeconds": 60,
              "TimeoutSeconds": 3600,
              "Retry": [
                {
                  "ErrorEquals": [
                    "States.Timeout",
                    "Lambda.ServiceException",
                    "Lambda.AWSLambdaException",
                    "Lambda.SdkClientException",
                    "Lambda.TooManyRequestsException"
                  ],
                  "IntervalSeconds": 5,
                  "MaxAttempts": 5,
                  "BackoffRate": 3
                }
              ],
              "Catch": [
                {
                  "ErrorEquals": [
                    "States.ALL"
                  ],
                  "Next": "CatchDeliveryHistoryErrors"
                }
              ],
              "OutputPath": "$.errors",
              "End": true
            },
            "CatchDeliveryHistoryErrors": {
              "Type": "Succeed"
            }
          }
        },
        {
          "StartAt": "SetMainReleaseDate",
          "States": {
            "SetMainReleaseDate": {
              "Type": "Task",
              "Resource": "${lambda_set_main_release_date_arn}",
              "HeartbeatSeconds": 60,
              "TimeoutSeconds": 3600,
              "Retry": [
                {
                  "ErrorEquals": [
                    "States.Timeout",
                    "Lambda.ServiceException",
                    "Lambda.AWSLambdaException",
                    "Lambda.SdkClientException",
                    "Lambda.TooManyRequestsException"
                  ],
                  "IntervalSeconds": 5,
                  "MaxAttempts": 5,
                  "BackoffRate": 3
                }
              ],
              "Catch": [
                {
                  "ErrorEquals": [
                    "States.ALL"
                  ],
                  "Next": "CatchReleaseDateErrors"
                }
              ],
              "Next": "StoreLinksAndPreOrder"
            },
            "CatchReleaseDateErrors": {
              "Type": "Succeed"
            },
            "StoreLinksAndPreOrder": {
              "Type": "Parallel",
              "Branches": [
                {
                  "StartAt": "SetPreOrderInfo",
                  "States": {
                    "SetPreOrderInfo": {
                      "Type": "Task",
                      "Resource": "${lambda_set_preorder_info_arn}",
                      "HeartbeatSeconds": 60,
                      "TimeoutSeconds": 3600,
                      "Retry": [
                        {
                          "ErrorEquals": [
                            "States.Timeout",
                            "Lambda.ServiceException",
                            "Lambda.AWSLambdaException",
                            "Lambda.SdkClientException",
                            "Lambda.TooManyRequestsException"
                          ],
                          "IntervalSeconds": 5,
                          "MaxAttempts": 5,
                          "BackoffRate": 3.0
                        }
                      ],
                      "Catch": [
                        {
                          "ErrorEquals": [
                            "States.ALL"
                          ],
                          "Next": "CatchPreorderInfoErrors"
                        }
                      ],
                      "OutputPath": "$.errors",
                      "End": true
                    },
                    "CatchPreorderInfoErrors": {
                      "Type": "Succeed"
                    }
                  }
                }
              ],
              "End": true
            }
          }
        }
      ],
      "Next": "DetectErrors"
    },
    "DetectErrors": {
      "Type": "Task",
      "Resource": "${lambda_detect_errors_arn}",
      "Retry": [
        {
          "ErrorEquals": [
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 5,
          "BackoffRate": 3
        }
      ],
      "Next": "CheckErrors"
    },
    "CheckErrors": {
      "Type": "Choice",
      "Choices": [
        {
          "Variable": "$.errors",
          "IsPresent": true,
          "Next": "WriteCatalogIngestionFailure"
        }
      ],
      "Default": "ValidateProduct"
    },
    "ValidateProduct": {
      "Type": "Task",
      "Resource": "${lambda_validate_product_arn}",
      "HeartbeatSeconds": 60,
      "TimeoutSeconds": 3600,
      "Retry": [
        {
          "ErrorEquals": [
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 5,
          "BackoffRate": 3.0
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "WriteCatalogIngestionFailure",
          "ResultPath": "$.errors"
        }
      ],
      "Next": "ValidateProductRetry"
    },
    "ValidateProductRetry": {
      "Type": "Choice",
      "Choices": [
        {
          "And": [
            {
              "Variable": "$.validate_product_retry_counter",
              "NumericGreaterThan": 0
            },
            {
              "Variable": "$.validate_product_retry_counter",
              "NumericLessThanEquals": 3
            }
          ],
          "Next": "ValidateProductRetryWait"
        }
      ],
      "Default": "WriteCatalogIngestionSuccess"
    },
    "ValidateProductRetryWait": {
      "Type": "Wait",
      "Seconds": 60,
      "Next": "ValidateProduct"
    },
    "WriteCatalogIngestionSuccess": {
      "Type": "Task",
      "Resource": "${lambda_write_catalog_ingestion_arn}",
      "Parameters": {
        "context.$": "$",
        "status": "Success"
      },
      "Retry": [
        {
          "ErrorEquals": [
            "OperationalError",
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 5,
          "BackoffRate": 3
        }
      ],
      "End": true
    },
    "WriteCatalogIngestionFailure": {
      "Type": "Task",
      "Resource": "${lambda_write_catalog_ingestion_arn}",
      "Parameters": {
        "context.$": "$",
        "status": "Failure"
      },
      "Retry": [
        {
          "ErrorEquals": [
            "OperationalError",
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 5,
          "BackoffRate": 3
        }
      ],
      "Next": "FailState"
    },
    "FailState": {
      "Type": "Fail"
    }
  }
}
