# Database Configuration
# Edit this file to change which database commands run against

# Database connection settings
$PSQL_PATH = "C:\Program Files\PostgreSQL\18\bin\psql.exe"
$DB_USER = "jellyfin"
$DB_NAME = "jellyfin_test2"  # ← Change this to switch databases
$DB_HOST = "192.168.129.253"
$DB_PORT = "6432"

# Export for use in other scripts
$global:PSQL_PATH = $PSQL_PATH
$global:DB_USER = $DB_USER
$global:DB_NAME = $DB_NAME
$global:DB_HOST = $DB_HOST
$global:DB_PORT = $DB_PORT

# Helper function to run psql commands
function Invoke-PSQL {
    param(
        [string]$Query,
        [string]$File,
        [string]$OutputFile
    )

    $baseCmd = "& `"$PSQL_PATH`" -h $DB_HOST -p $DB_PORT -U $DB_USER -d $DB_NAME"

    if ($File) {
        $cmd = "$baseCmd -f `"$File`""
    } elseif ($Query) {
        $cmd = "$baseCmd -c `"$Query`""
    } else {
        Write-Error "Must provide either -Query or -File parameter"
        return
    }

    if ($OutputFile) {
        $cmd += " > `"$OutputFile`""
    }

    Write-Host "Connecting to: $DB_NAME@$DB_HOST as $DB_USER" -ForegroundColor Cyan
    Invoke-Expression $cmd
}

# Display current configuration
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "Database Configuration Loaded" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "Database: $DB_NAME" -ForegroundColor Yellow
Write-Host "User: $DB_USER" -ForegroundColor Yellow
Write-Host "Host: $DB_HOST" -ForegroundColor Yellow
Write-Host "Port: $DB_PORT" -ForegroundColor Yellow
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "To change database, edit: db-config.ps1" -ForegroundColor Gray
Write-Host "Then run: . .\db-config.ps1" -ForegroundColor Gray
Write-Host ""
