$ErrorActionPreference = 'Stop'

$root = Split-Path -Parent $MyInvocation.MyCommand.Path
$backupRoot = Join-Path $root 'backups'

if (-not (Test-Path $backupRoot)) {
    New-Item -ItemType Directory -Path $backupRoot | Out-Null
}

$timestamp = Get-Date -Format 'yyyy-MM-dd_HHmmss'
$zipName = "Payslip_Project_$timestamp.zip"
$zipPath = Join-Path $backupRoot $zipName

$items = Get-ChildItem -Force -LiteralPath $root | Where-Object {
    $_.Name -ne 'backups' -and $_.Name -ne 'backup-project.ps1'
}

if ($items.Count -eq 0) {
    throw 'No project files found to back up.'
}

Compress-Archive -Path $items.FullName -DestinationPath $zipPath -Force

Write-Host "Backup created: $zipPath"
