#!/usr/bin/env bash
set -e

# Path to your existing wrapper
WRAPPER="/path/to/ansible/run"

# List of playbooks
PLAYBOOKS=("os_update_vms" "os_update_pve" "os_update_pve_verify" "os_update_pbs" "container_update" "app_update" "disk_cleanup" "automation_self_update" "dashy_fleet_audit" "dashy_selfhosting_coverage" "emby_tag_sync" "jellyfin_tag_sync" "Quit")

# Interactive menu
PS3="Select playbook to run (number): "

# Colored header (yellow)
YELLOW="\033[1;33m"
RESET="\033[0m"
echo -e "${YELLOW}=== Ansible Playbook Runner ===${RESET}"

select opt in "${PLAYBOOKS[@]}"; do
    case $opt in
        "os_update_vms"|"os_update_pve"|"os_update_pve_verify"|"os_update_pbs"|"container_update"|"app_update"|"disk_cleanup"|"automation_self_update"|"dashy_fleet_audit"|"dashy_selfhosting_coverage"|"emby_tag_sync"|"jellyfin_tag_sync")
            read -p "Dry run (--check)? [y/N]: " dry_run
            read -p "Limit to a single host? (leave blank for all): " limit_host

            ARGS=()
            if [[ "$dry_run" =~ ^[Yy]$ ]]; then
                ARGS+=(--check)
            fi
            if [ -n "$limit_host" ]; then
                ARGS+=(--limit "$limit_host")
            fi

            echo "Running playbook: $opt ${ARGS[*]}"
            "$WRAPPER" "$opt" "${ARGS[@]}"
            break
            ;;
        "Quit")
            echo "Exiting."
            exit 0
            ;;
        *)
            echo "Invalid selection. Please choose a number from the list."
            ;;
    esac
done
