# PowerShell script to set artifact naming based on version
param(
    [string]$ConfigType = "imex"
)

# Read the package.json to get the version
$packageJsonPath = Join-Path $PSScriptRoot "..\package.json"
$packageJson = Get-Content $packageJsonPath | ConvertFrom-Json
$version = $packageJson.version

Write-Host "Current version: $version"

# Determine the artifact suffix based on the version
$artifactSuffix = ""

if ($version -match "alpha") {
    $artifactSuffix = "alpha-${version}-"
    Write-Host "Detected alpha version, setting suffix to: $artifactSuffix"
}
elseif ($version -match "beta") {
    $artifactSuffix = "beta-${version}-"
    Write-Host "Detected beta version, setting suffix to: $artifactSuffix"
}
else {
    $artifactSuffix = ""
    Write-Host "Detected release version, no suffix will be added"
}

# Set the environment variable
$env:ARTIFACT_SUFFIX = $artifactSuffix

# Export for the current session
[Environment]::SetEnvironmentVariable("ARTIFACT_SUFFIX", $artifactSuffix, "Process")

Write-Host "ARTIFACT_SUFFIX set to: '$env:ARTIFACT_SUFFIX'"

# Return the suffix for use in other scripts
return $artifactSuffix
