# Build configuration
$configuration = "Release"
$baseOutputPath = ".\artifacts"

# Determine current OS and platform
$currentPlatform = "win-x64" # Since we're running PowerShell, we're on Windows
Write-Host "Building for current platform: $currentPlatform"

# Create output directories
$exeOutputPath = "$baseOutputPath\exe"
$nativeOutputPath = "$baseOutputPath\native"
New-Item -ItemType Directory -Force -Path $exeOutputPath | Out-Null
New-Item -ItemType Directory -Force -Path $nativeOutputPath | Out-Null

# Build executable
Write-Host "Building executable..."
dotnet publish `
    -c $configuration `
    -r $currentPlatform `
    --self-contained true `
    -p:PublishDir=$exeOutputPath

if ($LASTEXITCODE -ne 0) {
    Write-Host "Executable build failed. Check the error messages above."
    exit 1
}

# Build native shared library
Write-Host "Building native shared library..."
dotnet publish `
    -c $configuration `
    -r $currentPlatform `
    --self-contained true `
    -p:BuildType=lib `
    -p:PublishDir=$nativeOutputPath

if ($LASTEXITCODE -ne 0) {
    Write-Host "Library build failed. Check the error messages above."
    exit 1
}

Write-Host "Build complete. Outputs available at:"
Write-Host "Executable: $exeOutputPath"
Write-Host "Native library: $nativeOutputPath"