#!/usr/bin/env bash
set -euo pipefail
stpRoot="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
source "$stpRoot/lib/log.sh"

readonly easyEffectsApplicationDirectory="$HOME/.var/app/com.github.wwmm.easyeffects"
readonly outputFile="$stpRoot/secrets/easyEffectsConfig.zip"

easyEffectsDataExists() {
    [[ -d "$easyEffectsApplicationDirectory/config/easyeffects" ]] || [[ -d "$easyEffectsApplicationDirectory/data/easyeffects" ]]
}

if ! easyEffectsDataExists; then
    log::warn "Datos de EasyEffects no encontrados en: $easyEffectsApplicationDirectory"
    log::info "Asegurate de haber abierto EasyEffects al menos una vez antes de capturar"
    exit 0
fi

log::step "Capturando configuración de EasyEffects"
mkdir -p "$stpRoot/secrets"
rm -f "$outputFile"

(
    cd "$easyEffectsApplicationDirectory"
    find "config/easyeffects" "data/easyeffects" -not -type d 2>/dev/null \
        | zip -q "$outputFile" -@
)

log::ok "Guardado: secrets/easyEffectsConfig.zip ($(du -sh "$outputFile" | cut -f1))"
log::info "Commiteá secrets/easyEffectsConfig.zip antes de hacer push"
