#!/bin/bash

# Winamp MPRIS Bridge Installer (FreeDesktop/XDG compliant)

set -e

# Configuration
BIN_DIR="$HOME/.local/bin"
SERVICE_NAME="winamp-mpris.service"
SYSTEMD_USER_DIR="$HOME/.config/systemd/user"

echo "Installing Winamp MPRIS Bridge..."

# 1. Create necessary directories
echo "Creating directories..."
mkdir -p "$BIN_DIR"
mkdir -p "$SYSTEMD_USER_DIR"

# 2. Copy files to the correct locations
echo "Copying files..."
# Install the script to ~/.local/bin/winamp-mpris (removing .py extension for cleaner usage)
cp winamp_mpris.py "$BIN_DIR/winamp-mpris"
chmod +x "$BIN_DIR/winamp-mpris"

# Install the service file
cp "$SERVICE_NAME" "$SYSTEMD_USER_DIR/"

# 3. Reload systemd and enable/start the service
echo "Configuring systemd service..."
systemctl --user daemon-reload
systemctl --user enable "$SERVICE_NAME"
systemctl --user restart "$SERVICE_NAME"

echo "Installation complete!"
echo "Script installed to: $BIN_DIR/winamp-mpris"
echo "Logs available at: ~/.local/state/winamp-mpris/bridge.log"
echo "PID file at: \$XDG_RUNTIME_DIR/winamp-mpris.pid"

systemctl --user status "$SERVICE_NAME" --no-pager
