{
    "Comment": "Product Transfer State Machine",
    "StartAt": "EnsureDestinationArtists",
    "States": {
        "EnsureDestinationArtists": {
            "Type": "Task",
            "InputPath": "$$.Execution.Input",
            "Resource": "${ensure_artists_lambda_arn}",
            "Retry": [
                {
                    "ErrorEquals": ["States.ALL"],
                    "MaxAttempts": 3,
                    "IntervalSeconds": 10,
                    "BackoffRate": 2
                }
            ],
            "Catch": [
                {
                    "ErrorEquals": ["States.ALL"],
                    "Next": "HandleError",
                    "ResultPath": "$.error"
                }
            ],
            "Next": "ExecuteContentTransfer"
        },
        "ExecuteContentTransfer": {
            "Type": "Task",
            "InputPath": "$$.Execution.Input",
            "Resource": "${execute_content_transfer_lambda_arn}",
            "Retry": [
                {
                    "ErrorEquals": ["States.ALL"],
                    "MaxAttempts": 3,
                    "IntervalSeconds": 15,
                    "BackoffRate": 2
                }
            ],
            "Catch": [
                {
                    "ErrorEquals": ["States.ALL"],
                    "Next": "HandleError",
                    "ResultPath": "$.error"
                }
            ],
            "Next": "PostTransfer"
        },
        "PostTransfer": {
            "Type": "Parallel",
            "Branches": [
                {
                    "StartAt": "UpdateDimTables",
                    "States": {
                        "UpdateDimTables": {
                            "Type": "Task",
                            "InputPath": "$$.Execution.Input",
                            "Resource": "${update_dim_tables_lambda_arn}",
                            "Retry": [
                                {
                                    "ErrorEquals": ["States.ALL"],
                                    "MaxAttempts": 3,
                                    "IntervalSeconds": 10,
                                    "BackoffRate": 2
                                }
                            ],
                            "End": true
                        }
                    }
                },
                {
                    "StartAt": "EditAttachments",
                    "States": {
                        "EditAttachments": {
                            "Type": "Task",
                            "InputPath": "$$.Execution.Input",
                            "Resource": "${edit_attachments_lambda_arn}",
                            "Retry": [
                                {
                                    "ErrorEquals": ["States.ALL"],
                                    "MaxAttempts": 3,
                                    "IntervalSeconds": 10,
                                    "BackoffRate": 2
                                }
                            ],
                            "End": true
                        }
                    }
                }
            ],
            "Catch": [
                {
                    "ErrorEquals": ["States.ALL"],
                    "Next": "HandleError",
                    "ResultPath": "$.error"
                }
            ],
            "Next": "FinalizeJob"
        },
        "FinalizeJob": {
            "Type": "Task",
            "InputPath": "$$.Execution.Input",
            "Resource": "${finalize_job_lambda_arn}",
            "Retry": [
                {
                    "ErrorEquals": ["States.ALL"],
                    "MaxAttempts": 3,
                    "IntervalSeconds": 5,
                    "BackoffRate": 2
                }
            ],
            "Catch": [
                {
                    "ErrorEquals": ["States.ALL"],
                    "Next": "HandleError",
                    "ResultPath": "$.error"
                }
            ],
            "End": true
        },
        "HandleError": {
            "Type": "Task",
            "Parameters": {
                "job_id.$": "$$.Execution.Input.job_id",
                "error.$": "$.error"
            },
            "Resource": "${handle_error_lambda_arn}",
            "Retry": [
                {
                    "ErrorEquals": ["States.ALL"],
                    "MaxAttempts": 3,
                    "IntervalSeconds": 5,
                    "BackoffRate": 2
                }
            ],
            "Next": "JobFailed"
        },
        "JobFailed": {
            "Type": "Fail"
        }
    }
}
