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

# Load shared utilities
$utilsPath = Join-Path $PSScriptRoot '..\lib\utils.ps1'
. $utilsPath

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

# Shutdown services
Write-Step "Shutting down..."
docker compose down
if ($LASTEXITCODE -ne 0) {
    Write-Error-Custom "Failed to shut down services"
    exit $LASTEXITCODE
}
Write-Success "Services were shut down successfully!"

# Remove volumes
Write-Step "Removing volumes..."
docker volume remove -f evibes_prometheus-data
if ($LASTEXITCODE -ne 0) {
    Write-Warning-Custom "Failed to remove prometheus-data volume"
}
docker volume remove -f evibes_es-data
if ($LASTEXITCODE -ne 0) {
    Write-Warning-Custom "Failed to remove es-data volume"
}
Write-Success "Volumes were removed successfully!"

# Cleanup Docker
Write-Step "Cleaning up unused Docker data..."
docker system prune -a -f --volumes
if ($LASTEXITCODE -ne 0) {
    Write-Warning-Custom "Docker cleanup had issues, but continuing..."
}
Write-Success "Unused Docker data cleaned successfully!"

# Remove local files
Write-Step "Removing related files..."
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue ./media
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue ./static
Write-Success "Related files removed successfully!"

Write-Result ""
Write-Result "Bye-bye, hope you return later!"