#!/usr/bin/env pwsh
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
}

# Database backup
Write-Step "Starting database backup process..."
docker compose exec app uv run manage.py dbbackup
if ($LASTEXITCODE -ne 0) {
    Write-Error-Custom "Database backup failed"
    exit $LASTEXITCODE
}
Write-Success "Database backup created under ./dbbackup"

# Media backup
Write-Step "Starting media backup process..."
docker compose exec app uv run manage.py mediabackup
if ($LASTEXITCODE -ne 0) {
    Write-Error-Custom "Media backup failed"
    exit $LASTEXITCODE
}
Write-Success "Media backup created under ./dbbackup"

Write-Result ""
Write-Result "Backup completed successfully!"