param(
    $Action,
    [hashtable] $Arguments
)

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

Start-SoftwareInstaller @PSBoundParameters `
    -Installer {
        Install-ChocoPackage nextcloud-client -ArgumentList "-y","--params='/KeepUpdateCheck'";
    } `
    -UserConfigurator {
        if (-not (Test-Path $context.GetNextcloudConfigFile())) {
            Write-Information "Setting up Nextcloud configuration";

            Write-Information "Ensuring all Let's Encrypt certificates are cached";
            $null = Invoke-WebRequest https://valid-isrgrootx1.letsencrypt.org/;

            while (-not (Test-Path $context.GetNextcloudConfigFile())) {
                Write-Host "Nextcloud has been installed!";
                Read-Host "Please log in in the Nextcloud app and hit enter to continue";

                if (-not (Test-Path $context.GetNextcloudConfigFile())) {
                    Write-Error "The login seems to have failed. Please try again.";
                }
            }

            $context.Reboot();
            exit;
        }
    };