Install/OnPrem/Uninstall-Module.psm1

Import-Module "$PSScriptRoot\..\..\Common\Run-Pipelines.psm1" -Force
$ErrorActionPreference = "Stop"

function IsAllInOne {
    if($global:Configuration.system.hosting -ne "OnPrem") {
        return $false
    }
    if($global:Configuration.system.serverRole -ne "AllInOne") {
        return $false
    }

    return $true
}

function IsSolrRunningAsLocalService {
    if([string]::IsNullOrEmpty($global:Configuration.search.solr.serviceURL)) {
        return $true
    }
    return $false
}

function StartUninstallSitecore {
    [CmdletBinding()]
    Param
    (
        [switch]$Force
    )
    
    if(!(IsAllInOne)) {
        throw "SAF supports only uninstall of AllInOne (XP0 & XM0) instances..."
    }

    $pipeline = "uninstallSitecore-$($global:Configuration.system.sitecoreMode)"
    RunSteps -Pipeline $pipeline -Force:$Force
}

function StartUninstallSolr {
    [CmdletBinding()]
    Param
    (
        [switch]$Force
    )
    
    if(!(IsSolrRunningAsLocalService)) {
        throw "SAF supports only uninstall of Solr running as local service..."
    }

    $pipeline = "uninstallSolr"
    RunSteps -Pipeline $pipeline -Force:$Force
}

Export-ModuleMember -Function "StartUninstallSitecore"
Export-ModuleMember -Function "StartUninstallSolr"