Install/OnPrem/XP/Scaled/xConnectCollectionSearch/Install-CollectionSearch.ps1

. "$PSScriptRoot\..\..\..\..\InstallParams.ps1" -Force
. "$PSScriptRoot\..\..\..\Solr\SolrParams.ps1" -Force
Import-Module "$PSScriptRoot\..\..\..\..\..\Common\SSL\SSL-Module.psm1" -Force
Import-Module "$PSScriptRoot\..\..\..\Install-Module.psm1" -Force
$ErrorActionPreference = "Stop"

$prefix = $global:Configuration.prefix
$siteName = $global:Configuration.xConnect.collectionSearchHostName
$hostNames = @($siteName)
$license = $global:Configuration.license
$sqlServer = $global:Configuration.sql.serverName
$sqlSitecorePassword = $global:Configuration.sql.sitecorePassword
$installDir = $global:Configuration.xConnect.installDir
$environment = $global:Configuration.xConnect.environment
$logLevel = $global:Configuration.xConnect.logLevel
$solrURL = $SolrServiceURL
$package = Get-ChildItem -Path "$SAFInstallPackageDir\*" -Include *collectionsearch.scwdp.zip*
$sifConfiguration = GetSIFConfiguration -Name "xconnect-xp1-collectionsearch.json" -PackageName $package -DefaultValue "$PSScriptRoot\xconnect-xp1-collectionsearch.json"

$clientCert = BuildSitecoreClientCertName -Prefix $prefix
$serverCert = BuildSitecoreServerCertName -Prefix $prefix

Write-Output "Install xConnect Collection Search started..."

$sitecoreParams = @{
    Path                           = $sifConfiguration
    Package                        = $package.FullName
    LicenseFile                    = $license
    Sitename                       = $siteName
    XConnectCert                   = $clientCert
    SSLCert                        = $serverCert
    SqlDbPrefix                    = $prefix
    SolrCorePrefix                 = $prefix
    SqlCollectionUser              = "$($prefix)_collectionuser"
    SqlCollectionPassword          = $sqlSitecorePassword
    SqlProcessingPoolsUser         = "$($prefix)_processingpoolsuser"
    SqlProcessingPoolsPassword     = $sqlSitecorePassword
    SqlMarketingAutomationUser     = "$($prefix)_marketingautomationuser"
    SqlMarketingAutomationPassword = $sqlSitecorePassword
    SqlMessagingUser               = "$($prefix)_messaginguser"
    SqlMessagingPassword           = $sqlSitecorePassword
    SqlServer                      = $sqlServer
    SolrUrl                        = $solrURL
    XConnectEnvironment            = $environment
    XConnectLogLevel               = $logLevel
    InstallDirectory               = $installDir
}
Install-SitecoreConfiguration @sitecoreParams
AddWebBindings -SiteName $siteName -HostNames $hostNames
AddWebBindings -SiteName $siteName -HostNames $hostNames -SSLCert $serverCert

Write-Output "Install xConnect Collection Search done."