param(
    [string]$Root = 'C:\Users\seven\AletheiaBookTTS',
    [string]$DatasetName = 'student-dataset-100000',
    [string]$OutputName = 'student-100k-v1',
    [int]$Epochs = 20,
    [int]$BatchSize = 32,
    [double]$ValidationFraction = 0.05,
    [int]$EarlyStoppingPatience = 4,
    [switch]$Resume
)

$ErrorActionPreference = 'Stop'
$env:PYTHONUTF8 = '1'
$env:PYTHONIOENCODING = 'utf-8'
$python = Join-Path $Root '.venv\Scripts\python.exe'
$trainer = Join-Path $Root 'work\booktts_student.py'
$dataset = Join-Path $Root "work\$DatasetName"
$output = Join-Path $Root "work\$OutputName"
$arguments = @(
    $trainer, 'train', '--dataset', $dataset, '--output', $output,
    '--epochs', $Epochs, '--batch-size', $BatchSize,
    '--validation-fraction', $ValidationFraction,
    '--early-stopping-patience', $EarlyStoppingPatience
)
if ($Resume) { $arguments += '--resume' }
& $python @arguments
exit $LASTEXITCODE
