{
    "Comment": "A state machine that orchestrates Rekognition model training workflow with manifest freshness check",
    "StartAt": "Check Manifest Freshness",
    "States": {
        "Check Manifest Freshness": {
            "Type": "Task",
            "Resource": "${CheckManifestFreshnessFunctionArn}",
            "Retry": [
                {
                    "ErrorEquals": [
                        "States.TaskFailed"
                    ],
                    "IntervalSeconds": 15,
                    "MaxAttempts": 2,
                    "BackoffRate": 1.5
                }
            ],
            "Next": "Is Manifest Fresh"
        },
        "Is Manifest Fresh": {
            "Type": "Choice",
            "Choices": [
                {
                    "Variable": "$.manifest_fresh",
                    "BooleanEquals": true,
                    "Next": "Delete Datasets"
                }
            ],
            "Default": "Manifest Too Old"
        },
        "Manifest Too Old": {
            "Type": "Pass",
            "Result": {
                "statusCode": 200,
                "message": "Training skipped: Manifest file is too old (older than configured max age)"
            },
            "End": true
        },
        "Delete Datasets": {
            "Type": "Task",
            "Resource": "${DeleteDatasetsFunctionArn}",
            "Retry": [
                {
                    "ErrorEquals": [
                        "States.TaskFailed"
                    ],
                    "IntervalSeconds": 15,
                    "MaxAttempts": 2,
                    "BackoffRate": 1.5
                }
            ],
            "Next": "Split Manifest"
        },
        "Split Manifest": {
            "Type": "Task",
            "Resource": "${SplitManifestFunctionArn}",
            "Retry": [
                {
                    "ErrorEquals": [
                        "States.TaskFailed"
                    ],
                    "IntervalSeconds": 15,
                    "MaxAttempts": 2,
                    "BackoffRate": 1.5
                }
            ],
            "Next": "Create Dataset"
        },
        "Create Dataset": {
            "Type": "Task",
            "Resource": "${CreateDatasetFunctionArn}",
            "Retry": [
                {
                    "ErrorEquals": [
                        "States.TaskFailed"
                    ],
                    "IntervalSeconds": 15,
                    "MaxAttempts": 2,
                    "BackoffRate": 1.5
                }
            ],
            "Next": "Wait For Datasets"
        },
        "Wait For Datasets": {
            "Type": "Wait",
            "Seconds": 30,
            "Next": "Check Dataset Status"
        },
        "Check Dataset Status": {
            "Type": "Task",
            "Resource": "${CheckDatasetStatusFunctionArn}",
            "Retry": [
                {
                    "ErrorEquals": [
                        "States.TaskFailed"
                    ],
                    "IntervalSeconds": 15,
                    "MaxAttempts": 2,
                    "BackoffRate": 1.5
                }
            ],
            "Next": "Are Datasets Ready"
        },
        "Are Datasets Ready": {
            "Type": "Choice",
            "Choices": [
                {
                    "Variable": "$.datasets_ready",
                    "BooleanEquals": true,
                    "Next": "Start Training"
                }
            ],
            "Default": "Wait For Datasets"
        },
        "Start Training": {
            "Type": "Task",
            "Resource": "${StartTrainingFunctionArn}",
            "Retry": [
                {
                    "ErrorEquals": [
                        "States.TaskFailed"
                    ],
                    "IntervalSeconds": 15,
                    "MaxAttempts": 2,
                    "BackoffRate": 1.5
                }
            ],
            "Next": "Wait For Training"
        },
        "Wait For Training": {
            "Type": "Wait",
            "Seconds": 300,
            "Next": "Check Training Status"
        },
        "Check Training Status": {
            "Type": "Task",
            "Resource": "${CheckTrainingStatusFunctionArn}",
            "Retry": [
                {
                    "ErrorEquals": [
                        "States.TaskFailed"
                    ],
                    "IntervalSeconds": 15,
                    "MaxAttempts": 2,
                    "BackoffRate": 1.5
                }
            ],
            "Next": "Is Training Complete"
        },
        "Is Training Complete": {
            "Type": "Choice",
            "Choices": [
                {
                    "Variable": "$.training_complete",
                    "BooleanEquals": true,
                    "Next": "Training Complete"
                }
            ],
            "Default": "Wait For Training"
        },
        "Training Complete": {
            "Type": "Pass",
            "End": true
        }
    }
} 