#!/bin/bash

# --- Dynasty Metadata ---
VERSION="1.0.1"
REMOTE_URL="https://your-gitea-link.com/raw/dynr" # <--- POINT TO YOUR GITEA RAW URL
BLUE='\033[38;5;45m' 
PURPLE='\033[38;5;127m'
GOLD='\033[38;5;178m'
NC='\033[0m'

# --- Update Logic ---
check_update() {
    # Silently check Gitea for the latest version string
    LATEST_VERSION=$(curl -s "$REMOTE_URL" | grep -m 1 "VERSION=" | cut -d '"' -f 2)
    
    if [[ "$LATEST_VERSION" != "$VERSION" && ! -z "$LATEST_VERSION" ]]; then
        echo -e "${GOLD}🐉 A new Dynasty Scroll (v$LATEST_VERSION) is available.${NC}"
        read -p "Apply update? (y/n): " choice
        if [[ "$choice" == "y" ]]; then
            curl -sSL "$REMOTE_URL" -o /usr/local/bin/dynr
            chmod +x /usr/local/bin/dynr
            echo -e "${BLUE}✨ Update complete. Please restart your command.${NC}"
            exit 0
        fi
    fi
}

# --- RClone Transfer Wizard ---
run_rclone_wizard() {
    # (The space-safe, color-coded logic from our previous step goes here)
    # Including the find -print0 | fzf --read0 logic
    echo -e "${PURPLE}--- DYNASTY RCLONE WIZARD v$VERSION ---${NC}"
    # ... [Rest of the transfer logic] ...
}

# --- Main Router ---
case "$1" in
    update)
        check_update
        ;;
    rclone)
        [[ "$2" == "transfer" ]] && run_rclone_wizard || echo "Usage: dynr rclone transfer"
        ;;
    *)
        echo -e "${PURPLE}Dynasty Revolution CLI${NC} v$VERSION"
        echo -e "${GOLD}Commands:${NC}"
        echo -e "  ${BLUE}rclone transfer${NC} - Smart transfer"
        echo -e "  ${BLUE}update${NC}          - Check for new features"
        ;;
esac