{
  "Comment": "Handles Asset fingerprints and ingesting information from it into The Orchard Graph",
  "StartAt": "InputChoice",
  "States": {
    "InputChoice": {
      "Type": "Choice",
      "Choices": [
        {
          "And": [
            {
              "Variable": "$.operation",
              "StringEquals": "created"
            },
            {
              "Variable": "$.label",
              "StringEquals": "OrchardAsset"
            }
          ],
          "Next": "ACRFingerprinter"
        },
        {
            "And": [
                {
                    "Variable": "$.operation",
                    "StringEquals": "created"
                },
                {
                    "Variable": "$.label",
                    "StringEquals": "Track"
                }
            ],
            "Next": "SRCreate"
        },
        {
            "And": [
                {
                    "Variable": "$.operation",
                    "StringEquals": "updated"
                },
                {
                    "Variable": "$.label",
                    "StringEquals": "Vendor"
                }
            ],
            "Next": "SRFanout"
        },
        {
            "And": [
                {
                    "Variable": "$.operation",
                    "StringEquals": "updated"
                },
                {
                    "Variable": "$.label",
                    "StringEquals": "SubAccount"
                }
            ],
            "Next": "SRFanout"
        }
      ],
      "Default": "SRAddVersion"
    },
    "ACRFingerprinter": {
      "Type": "Task",
      "Resource": "${lambda_acr_fingerprinter_arn}",
      "Parameters": {
        "execution_name.$": "$$.Execution.Name",
        "state_machine_name.$": "$$.StateMachine.Name",
        "execution_start_time.$": "$$.Execution.StartTime",
        "asset.$": "$.payload.after.properties"
      },
      "Retry": [
        {
          "ErrorEquals": [
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "RetryableException"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 5,
          "BackoffRate": 3
        },
        {
          "ErrorEquals": [
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 10,
          "MaxAttempts": 50,
          "BackoffRate": 1.1
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "TooSmallFingerprint",
            "TooLargeFingerprint",
            "UnableToFingerprint",
            "FileTooLarge"
          ],
          "Next": "ShortCircuit"
        }
      ],
      "Next": "SRCreate"
    },
    "SRCreate": {
      "Type": "Task",
      "Resource": "${lambda_sr_create_arn}",
      "HeartbeatSeconds": 60,
      "TimeoutSeconds": 3600,
      "Retry": [
        {
          "ErrorEquals": [
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException",
            "RetryableException"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 5,
          "BackoffRate": 3
        }
      ],
      "Next": "AddVersionChoice"
    },
    "AddVersionChoice": {
      "Type": "Choice",
      "Choices": [
        {
          "Variable": "$.sound_recording_ids[0]",
          "IsPresent": false,
          "Next": "ShortCircuit"
        }
      ],
      "Default": "SRAddVersion"
    },
    "ShortCircuit": {
      "Type": "Succeed"
    },
    "SRFanout": {
        "Type": "Task",
        "Resource": "${lambda_sr_fanout_arn}",
        "HeartbeatSeconds": 60,
        "TimeoutSeconds": 3600,
        "Retry": [
          {
            "ErrorEquals": [
              "States.Timeout",
              "Lambda.ServiceException",
              "Lambda.AWSLambdaException",
              "Lambda.SdkClientException",
              "Lambda.TooManyRequestsException",
              "RetryableException"
            ],
            "IntervalSeconds": 5,
            "MaxAttempts": 5,
            "BackoffRate": 3
          }
        ],
        "Next": "ShortCircuit"
    },
    "SRAddVersion": {
      "Type": "Task",
      "Resource": "${lambda_sr_add_version_arn}",
      "HeartbeatSeconds": 60,
      "TimeoutSeconds": 3600,
      "Retry": [
        {
          "ErrorEquals": [
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "RetryableException",
            "ReadTimeout"
          ],
          "IntervalSeconds": 5,
          "MaxAttempts": 5,
          "BackoffRate": 3
        },
        {
          "ErrorEquals": [
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 60,
          "MaxAttempts": 10,
          "BackoffRate": 1.25
        }
      ],
      "End": true
    }
  }
}
