Core/Uninstall-Module.psm1

$ErrorActionPreference = "Stop"

function IsAllInOne {
    if($SAFConfiguration.system.hosting -ne "OnPrem") {
        return $false
    }
    if($SAFConfiguration.system.serverRole -ne "AllInOneQuickly") {
        return $false
    }

    return $true
}

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

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

    RunPipeline -DefinitionFile $SAFUninstallPipelines -Name "uninstallSitecore" -Force:$Force
}

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

    RunPipeline -DefinitionFile $SAFUninstallPipelines -Name "uninstallSolr" -Force:$Force
}

Export-ModuleMember -Function "UninstallSitecore"
Export-ModuleMember -Function "UninstallSolr"