#!/usr/bin/env bash
# android_push — Push file/dir from WSL to Android device via adb push.
set -euo pipefail

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

android_push() {
    local serial local_path remote_path win_local

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

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

    if [[ ! -e "$local_path" ]]; then
        echo "android_push: '$local_path' not found." >&2
        return 1
    fi

    win_local=$(adb_wsl_to_win "$local_path")

    adb_s "$serial" push "$win_local" "$remote_path"
    echo "pushed: $local_path → $remote_path on $serial"
}

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