#!/usr/bin/env bash
# android_pull — Pull file/dir from Android device to WSL via adb pull.

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/adb_wsl.sh"

android_pull() {
    local serial remote local_path win_local

    adb_pick_serial "$@" || exit 3
    local serial="$ADB_PICK_SERIAL"
    set -- "${ADB_PICK_REST[@]}"

    remote="${1:?remote_path required}"
    local_path="${2:?local_path required}"

    mkdir -p "$(dirname "$local_path")"

    win_local=$(adb_wsl_to_win "$local_path")

    adb_s "$serial" pull "$remote" "$win_local"

    echo "pulled: $remote → $local_path from $serial"
}

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
    android_pull "$@"
fi
