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

readonly wireplumberStateDirectory="$HOME/.local/state/wireplumber"
readonly outputFile="$stpRoot/secrets/wireplumberState.zip"

wireplumberStateExists() {
    [[ -d "$wireplumberStateDirectory" ]]
}

if ! wireplumberStateExists; then
    log::warn "Estado de WirePlumber no encontrado en: $wireplumberStateDirectory"
    log::info "Asegurate de haber conectado los auriculares bluetooth al menos una vez"
    exit 0
fi

log::step "Capturando estado de WirePlumber"
mkdir -p "$stpRoot/secrets"
rm -f "$outputFile"

(
    cd "$HOME/.local/state"
    find "wireplumber" -not -type d | zip -q "$outputFile" -@
)

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