#!/bin/bash

restorePickSnapshot()
{
    local app_name="$1"
    local idx="$2"
    local snapshot_arg="$3"
    local host="${4:-$CFG_INSTALL_NAME}"

    if [[ -z "$idx" ]]; then
        idx=$(resticEnabledLocations | head -1)
    fi

    if [[ -z "$idx" ]]; then
        isError "No backup locations available"
        return 1
    fi

    if [[ "$snapshot_arg" == "latest" || -z "$snapshot_arg" ]]; then
        local id
        id=$(engineSnapshotLatestId "$idx" "$app_name" "$host")
        if [[ -z "$id" ]]; then
            isError "No snapshots found for app=$app_name on host=$host in $(resticLocationName "$idx")"
            return 1
        fi
        echo "$idx:$id"
    else
        echo "$idx:$snapshot_arg"
    fi
}
