param(
    $Action,
    [hashtable] $Arguments
)

& {
    param($Parameters)
    . "$PSScriptRoot/../../Scripts/Restoration.ps1";
    . "$PSScriptRoot/../../../Common/Scripts/BrowserAutomation.ps1";
    . "$PSScriptRoot/../../../Common/Scripts/Software.ps1";
    . "$PSScriptRoot/../../../Common/Scripts/System.ps1";

    $path = "$env:Public/Documents/reWASD";

    Start-SoftwareInstaller @Parameters `
        -Backup {
            Add-BackupArtifacts -Path "reWASD" -Source $path `
                -Exclude @(
                    "Logs",
                    "Presets",
                    "Profiles/Desktop",
                    "Profiles/Duality",
                    "Profiles/Handheld",
                    "Profiles/Fortnite",
                    "Profiles/PS4 Remote*",
                    "Profiles/Switch console",
                    "Profiles/Switch to Xbox 360",
                    "Profiles/Valorant",
                    "Profiles/xCloud"
                );
        } `
        -Installer {
            Write-Host "Downloading reWASD…";
            $dir = New-TemporaryDirectory;
            $file = Start-BrowserDownload -URL "https://rewasd.com/" -ButtonSelector 'a.btn-default[href="#"]' -OutDir $dir -Timeout 1;

            Write-Host "Installing reWASD…";
            Start-Process -Wait -FilePath $($file.FullName) -ArgumentList "/S";
            Remove-Item -Recurse $dir;
            Remove-DesktopIcon "*reWASD*";
        } `
        -Configurator {
            Expand-BackupArtifacts -Path "reWASD" -Target $path;
        };
} $PSBoundParameters;