modules/Config.psm1

using module '.\Enums.psm1'
using module '.\Helper\ObjectHelper.psm1'

class Config{
    #region Properties

    static [string] $globalSettingsFile = '~\PowerShell\SportsbookXray\global.settings.json'
    static [string] $userSettingsFile = '~\PowerShell\SportsbookXray\local.settings.json'

    [PSCustomObject] $autoUpdate
    [string] $auditLogFolder

    [hashtable] $endpoints
    [hashtable] $processors
    [hashtable] $downloaders
    [hashtable] $modules

    [double[]] $percentile

    [PSCustomObject] $jira
    [PSCustomObject] $smtp
    [PSCustomObject] $templates
    #endregion

    #region Constructors

    hidden Config() {
        # Load global settings and merge user preferences
        $settings = [ObjectHelper]::MergeObject($this.LoadGlobalSettings(), $this.LoadUserSettings())

        if ($settings){
            $global:DEBUG = $settings.debug
            $global:VERBOSE = $settings.verbose

            $this.autoUpdate = $settings.autoUpdate
            $this.auditLogFolder = $settings.auditLogFolder

            $this.endpoints = @{}
            foreach ($operator in $settings.endpoints.PSObject.Properties){
                $this.endpoints.Add([OPERATOR]($operator.Name), $operator.Value)
            }

            $this.processors = @{}
            foreach ($item in $settings.processors.PSobject.Properties) {
                $this.processors.Add([SOURCE_TYPE]($item.Name), $item.Value)
            }

            $this.downloaders = @{}
            foreach ($item in $settings.downloaders.PSobject.Properties) {
                $this.downloaders.Add($item.Name, $item.Value)
            }

            $this.modules = @{}
            foreach ($item in $settings.modules.PSobject.Properties) {
                $this.modules.Add([MODULE]$item.Name, $item.Value)
            }

            $this.percentile = $settings.percentile

            $this.jira = $settings.jira
            $this.templates = $settings.templates
            $this.smtp = $settings.smtp
        }
        else {
            throw "Cannot find settings file, please create it before you proceed with the analysis!"
        }
    }

    static [Config] Load(){
        return [Config]::new()
    }

    #endregion

    hidden [PSCustomObject] LoadGlobalSettings(){
        return $this.LoadSettings([Config]::globalSettingsFile)
    }

    hidden [PSCustomObject] LoadUserSettings(){
        return $this.LoadSettings([Config]::userSettingsFile)
    }

    hidden [PSCustomObject] LoadSettings([string] $settingsFile){
        $settings = $null

        if (Test-Path $settingsFile){
            $settings = (Get-Content -Path $settingsFile | ConvertFrom-Json)
        }

        return $settings
    }

    static [PSCustomObject] DownloadSettings([string] $urlSettings){
        $newSettings = (Invoke-WebRequest -Method GET -uri $urlSettings)
        $newSettings.content | Out-File -FilePath ([Config]::globalSettingsFile)

        return ($newSettings.content)
    }
}