<#
.SYNOPSIS
    Loads DBAOps configuration from DBAOps.config.json
.DESCRIPTION
    Reads InstallPath, CentralServer, Database from config file.
    Default config path: same folder as script, parent Config\DBAOps.config.json
.EXAMPLE
    $cfg = .\Get-DBAOpsConfig.ps1
    $cfg.InstallPath
#>
param(
    [string]$ConfigPath = $null
)

$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$defaultConfigPath = Join-Path (Split-Path -Parent $scriptDir) "Config\DBAOps.config.json"

if (-not $ConfigPath) {
    $ConfigPath = $defaultConfigPath
}

if (-not (Test-Path $ConfigPath)) {
    Write-Warning "Config not found: $ConfigPath"
    return @{
        InstallPath   = "M:\RHOYLLE INNOVATION EMPIRE LLC\DBAOps Futuristic Enterprise"
        CentralServer = $env:COMPUTERNAME
        Database      = "DBAOpsRepository"
    }
}

try {
    $json = Get-Content $ConfigPath -Raw -Encoding UTF8 | ConvertFrom-Json
    return @{
        InstallPath   = if ($json.InstallPath) { $json.InstallPath -replace '\\+', '\' } else { "M:\RHOYLLE INNOVATION EMPIRE LLC\DBAOps Futuristic Enterprise" }
        CentralServer = if ($json.CentralServer) { $json.CentralServer } else { $env:COMPUTERNAME }
        Database      = if ($json.Database) { $json.Database } else { "DBAOpsRepository" }
    }
} catch {
    Write-Warning "Failed to load config: $_"
    return @{
        InstallPath   = "M:\RHOYLLE INNOVATION EMPIRE LLC\DBAOps Futuristic Enterprise"
        CentralServer = $env:COMPUTERNAME
        Database      = "DBAOpsRepository"
    }
}
