Common/Initialization-Module.psm1

Import-Module "$PSScriptRoot\Utils-Module.psm1" -Force
$ErrorActionPreference = "Stop"
function ConfigureChoco {
    Write-Output "SAF loves the latest Chocolatey and is getting it..."
    try {
        choco | Out-Null
        Write-Output "Chocolatey is installed. Checking for updates..."
        choco upgrade chocolatey --limitoutput --confirm
    }
    catch {
        Write-Output "Chocolatey is not installed. Installing..."
        Invoke-WebRequest https://chocolatey.org/install.ps1 -UseBasicParsing | Invoke-Expression
    }
    choco feature enable -n allowGlobalConfirmation | Out-Null
    
    Write-Output "SAF is happy with having the latest Choco!"
}

function ConfigurePSGallery {
    Write-Output "SAF is ensuring NuGet package provider..."
    Install-PackageProvider NuGet -Force | Out-Null

    # Ensure Trusted, so that users are not prompted before installing modules from that source.
    Write-Output "SAF is trusting PSGallery..."
    Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
    LoadLatestPSModule -Name PowerShellGet
    LoadLatestPSModule -Name PackageManagement
}

Export-ModuleMember -Function "ConfigureChoco"
Export-ModuleMember -Function "ConfigurePSGallery"