param(
    [string]$RevitYear = "2026"
)

$ErrorActionPreference = "Stop"

try {
    $addinRoot = Join-Path $env:APPDATA "Autodesk\Revit\Addins\$RevitYear"
    $installDir = Join-Path $addinRoot "QART BIM Composer"
    $manifestPath = Join-Path $addinRoot "QART BIM Composer.addin"

    if (Test-Path $manifestPath) {
        Remove-Item -LiteralPath $manifestPath -Force
    }

    if (Test-Path $installDir) {
        Remove-Item -LiteralPath $installDir -Recurse -Force
    }

    Write-Host ""
    Write-Host "QART BIM Composer rimosso da Revit $RevitYear." -ForegroundColor Green
    Write-Host "Riavvia Revit se era aperto."
    Read-Host "Premi INVIO per chiudere"
}
catch {
    Write-Host ""
    Write-Host "Disinstallazione non riuscita." -ForegroundColor Red
    Write-Host $_.Exception.Message -ForegroundColor Yellow
    Read-Host "Premi INVIO per chiudere"
    exit 1
}
