$ErrorActionPreference = "Stop"

$siteRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).ProviderPath

$publicFiles = @(
    "index.html",
    "site.css",
    "site.js",
    "Resume_Jason_Eugene_Garrison.pdf",
    "Resume_Jason_Eugene_Garrison.docx"
)

foreach ($file in $publicFiles) {
    $path = Join-Path $siteRoot $file
    if (Test-Path -LiteralPath $path) {
        try {
            icacls $path /grant "*S-1-1-0:RX" | Out-Null
        } catch {
            Write-Warning "Could not update public permissions for ${file}: $($_.Exception.Message)"
        }
    }
}

foreach ($privatePath in @(".old", "scripts", "README.md", ".htaccess")) {
    $path = Join-Path $siteRoot $privatePath
    if (Test-Path -LiteralPath $path) {
        try {
            if ($privatePath -eq ".old") {
                icacls $path /remove:g "*S-1-1-0" | Out-Null
            } else {
                icacls $path /remove:g "*S-1-1-0" /T | Out-Null
            }
        } catch {
            Write-Warning "Could not update private permissions for ${privatePath}: $($_.Exception.Message)"
        }
    }
}

Write-Host "Published file permissions updated."
