Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'

$repoRoot = Resolve-Path (Join-Path $PSScriptRoot '..\..')
$protoRoot = Join-Path $repoRoot 'src\ZB.MOM.WW.MxGateway.Contracts\Protos'
$outputRoot = Join-Path $PSScriptRoot 'src\zb_mom_ww_mxgateway\generated'
$python = 'C:\Users\dohertj2\AppData\Local\Programs\Python\Python312\python.exe'

if (-not (Test-Path $python)) {
    throw "Python was not found at $python. See docs/ToolchainLinks.md."
}

New-Item -ItemType Directory -Path $outputRoot -Force | Out-Null
Get-ChildItem -Path (Join-Path $outputRoot '*_pb2.py') -File | Remove-Item
Get-ChildItem -Path (Join-Path $outputRoot '*_pb2_grpc.py') -File | Remove-Item

& $python -m grpc_tools.protoc `
    "-I$protoRoot" `
    "--python_out=$outputRoot" `
    "--grpc_python_out=$outputRoot" `
    mxaccess_gateway.proto `
    mxaccess_worker.proto `
    galaxy_repository.proto
