#!/bin/bash
# ================================================================
# full_reset.sh — KOMPLET nulstilling af LineDance-systemet
#
# Kør dette script på APP-SERVEREN:
#   bash full_reset.sh
#
# Herefter skal du selv:
#   docker compose down && docker compose up -d --build
# ================================================================
set -e

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

echo ""
echo -e "${RED}╔══════════════════════════════════════════════════════╗${NC}"
echo -e "${RED}║     KOMPLET NULSTILLING — LINEDANCE AFSPILLER        ║${NC}"
echo -e "${RED}║  Sletter ALT: sange, danse, playlister, synk-data    ║${NC}"
echo -e "${RED}╚══════════════════════════════════════════════════════╝${NC}"
echo ""
echo -e "${YELLOW}Dette kan IKKE fortrydes. Al data går tabt.${NC}"
echo ""
read -p "Skriv 'SLET ALT' for at fortsætte: " confirm
[ "$confirm" = "SLET ALT" ] || { echo "Afbrudt."; exit 1; }

COMPOSE_DIR="/opt/docker/linedanceafspiller/linedance-api"

# ── MySQL: drop og genskab tom database ───────────────────────
echo ""
echo -e "${YELLOW}▶ Dropper og genskaber MySQL-database...${NC}"
docker compose -f "$COMPOSE_DIR/docker-compose.yml" exec -T db \
  mysql -u root -proot << 'MYSQL'
DROP DATABASE IF EXISTS linedance;
CREATE DATABASE linedance CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
MYSQL
echo -e "${GREEN}  ✓ MySQL klar — tom database oprettet${NC}"

# ── Færdig ────────────────────────────────────────────────────
echo ""
echo -e "${GREEN}╔══════════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║  ✓ Server-database nulstillet                        ║${NC}"
echo -e "${GREEN}╚══════════════════════════════════════════════════════╝${NC}"
echo ""
echo "Gør nu dette:"
echo "  1. Rebuild og genstart Docker:"
echo "     cd $COMPOSE_DIR"
echo "     docker compose down && docker compose up -d --build"
echo ""
