# Wipe production tenant DB so setup wizard can run again (DESTRUCTIVE).
#Requires -Version 5.1
$ErrorActionPreference = "Stop"
. (Join-Path $PSScriptRoot "production.local.ps1")

Write-Host "This DELETES all companies and users on $ServerIp" -ForegroundColor Red
$confirm = Read-Host "Type YES to continue"
if ($confirm -ne "YES") { exit 1 }

$sshArgs = @("-o", "ServerAliveInterval=30")
if ($SshKeyPath -and (Test-Path $SshKeyPath)) {
    $sshArgs = @("-i", $SshKeyPath, "-o", "IdentitiesOnly=yes") + $sshArgs
}

$script = Join-Path $PSScriptRoot "reset-cloud-setup.sh"
scp @sshArgs $script "root@${ServerIp}:/tmp/reset-cloud-setup.sh"
ssh @sshArgs "root@$ServerIp" "sed -i 's/\r$//' /tmp/reset-cloud-setup.sh; chmod +x /tmp/reset-cloud-setup.sh; echo YES | bash /tmp/reset-cloud-setup.sh"

Write-Host "Fresh setup: https://$Domain/setup" -ForegroundColor Green
