#!/bin/bash
# ================================================================
# reset_local.sh — Nulstil SQLite på desktop-maskinen
# Kør på den PC hvor LineDance-appen kører
# ================================================================
set -e

GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'

echo ""
echo -e "${YELLOW}▶ Finder SQLite-database...${NC}"

SQLITE_DB=""
for candidate in \
    "$HOME/.local/share/LineDanceAfspiller/library.db" \
    "$HOME/.linedance/library.db" \
    "$HOME/AppData/Local/LineDanceAfspiller/library.db"; do
    if [ -f "$candidate" ]; then
        SQLITE_DB="$candidate"
        break
    fi
done

if [ -z "$SQLITE_DB" ]; then
    FOUND=$(find "$HOME" -name "library.db" 2>/dev/null | head -1)
    [ -n "$FOUND" ] && SQLITE_DB="$FOUND"
fi

if [ -n "$SQLITE_DB" ]; then
    BACKUP="${SQLITE_DB}.backup_$(date +%Y%m%d_%H%M%S)"
    cp "$SQLITE_DB" "$BACKUP"
    rm "$SQLITE_DB"
    echo -e "${GREEN}  ✓ Slettet: $SQLITE_DB${NC}"
    echo "  Backup gemt: $BACKUP"
else
    echo -e "${GREEN}  ✓ Ingen SQLite-fil fundet — appen starter allerede frisk${NC}"
fi

echo ""
echo -e "${GREEN}✓ Lokal database nulstillet${NC}"
echo "Start nu LineDance-appen — den genskaber databasen automatisk."
echo ""
