# setup.ps1 - vytvor .venv a nainstaluj zavislosti
# Spustit jednou po naklonovani projektu:
#   .\setup.ps1

$PythonExe = "C:\Python\python.exe"
$VenvDir   = Join-Path $PSScriptRoot ".venv"

# kontrola Pythonu
if (-not (Test-Path $PythonExe)) {
    Write-Error "Python nenalezen na '$PythonExe'. Uprav cestu v setup.ps1."
    exit 1
}

Write-Host "Python: $PythonExe"
& $PythonExe --version

# vytvoreni venv
if (Test-Path $VenvDir) {
    Write-Host ".venv jiz existuje, preskakuji vytvoreni."
} else {
    Write-Host "Vytvarim .venv ..."
    & $PythonExe -m venv $VenvDir
    if ($LASTEXITCODE -ne 0) { Write-Error "Nepodarilo se vytvorit venv."; exit 1 }
}

# instalace zavislosti
$Pip = Join-Path $VenvDir "Scripts\pip.exe"
Write-Host "Instaluji zavislosti z requirements.txt ..."
& $Pip install --upgrade pip --quiet
& $Pip install -r (Join-Path $PSScriptRoot "requirements.txt")
if ($LASTEXITCODE -ne 0) { Write-Error "pip install selhal."; exit 1 }

# playwright browsers
$Playwright = Join-Path $VenvDir "Scripts\playwright.exe"
Write-Host "Instaluji Playwright browsery (chromium) ..."
& $Playwright install chromium
if ($LASTEXITCODE -ne 0) {
    Write-Warning "Playwright install chromium selhal - zkus rucne: .venv\Scripts\playwright install chromium"
}

Write-Host ""
Write-Host "Hotovo! Aktivuj prostredi prikazem:"
Write-Host "  .venv\Scripts\Activate.ps1"
