# Removes the QBooking Print Client scheduled task and program files.
# Keeps C:\ProgramData\QBooking\print-client (config + guid + logs) so a
# reinstall keeps the same identity; delete that folder manually for a full
# wipe.
$ErrorActionPreference = "Stop"
$taskName = "QBookingPrintClient"
$dest = Join-Path $env:ProgramFiles "QBooking\PrintClient"

$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isAdmin) {
  Start-Process powershell.exe -Verb RunAs -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Wait
  exit
}

Unregister-ScheduledTask -TaskName $taskName -Confirm:$false -ErrorAction SilentlyContinue
Get-Process -Name "qbooking-print-client" -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
Start-Sleep -Seconds 1
Remove-Item -Recurse -Force -Path $dest -ErrorAction SilentlyContinue

Write-Output "Removed task '$taskName' and $dest."
Write-Output "Config/logs kept at $env:ProgramData\QBooking\print-client (delete manually for a full wipe)."
