Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'

.\scripts\Windows\starter.ps1
if ($LASTEXITCODE -ne 0) {
    exit $LASTEXITCODE
}

Write-Host "Shutting down..." -ForegroundColor Magenta
docker compose down
if ($LASTEXITCODE -ne 0) {
    exit $LASTEXITCODE
}
Write-Host "Services were shut down successfully!" -ForegroundColor Green

Write-Host "Removing volumes..." -ForegroundColor Magenta
docker volume remove -f evibes_prometheus-data
if ($LASTEXITCODE -ne 0) {
    exit $LASTEXITCODE
}
docker volume remove -f evibes_es-data
if ($LASTEXITCODE -ne 0) {
    exit $LASTEXITCODE
}
Write-Host "Volumes were removed successfully!" -ForegroundColor Green

Write-Host "Cleaning up unused Docker data..." -ForegroundColor Magenta
docker system prune -a -f --volumes
if ($LASTEXITCODE -ne 0) {
    exit $LASTEXITCODE
}
Write-Host "Unused Docker data cleaned successfully!" -ForegroundColor Green

Write-Host "Removing related files..." -ForegroundColor Magenta
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue ./services_data
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue ./media
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue ./static
Write-Host "Related files removed successfully!" -ForegroundColor Green

Write-Host "Bye-bye, hope you return later!" -ForegroundColor Red