using namespace Microsoft.Win32;

param(
    $Action,
    [hashtable] $Arguments
)

. "$PSScriptRoot/../../Scripts/Software.ps1";

Start-SoftwareInstaller @PSBoundParameters `
    -Installer {
        param(
            [scriptblock] $Installer
        )

        & $Installer -Action ([InstallerAction]::Configure)
    } `
    -Configurator {
        $nativeProfile = powershell -c '$PROFILE';
        $null = New-Item -Force $nativeProfile;
        choco install -y --force chocolatey;
        Copy-Item -Force $nativeProfile $PROFILE;

        Push-Location ~;
        $files = @($nativeProfile, $PROFILE) | ForEach-Object { Resolve-Path -Relative $_ };
        Pop-Location;

        foreach ($path in $files) {
            $fullName = "$env:SystemDrive/Users/Default/$path";
            $dirName = Split-Path -Parent $fullName;

            if (-not (Test-Path -PathType Container $dirName)) {
                $null = New-Item -Force -ItemType Directory $dirName;
            }

            Copy-Item -Force ~/"$path" $fullName;
        }

        Import-Module "$env:ChocolateyInstall/helpers/chocolateyProfile.psm1";
    };