public/Message/Compare-Messages.ps1

using module '..\..\modules\Enums.psm1'
using module '..\..\modules\Helper\DateTimeHelper.psm1'
using module '..\..\modules\Helper\StringHelper.psm1'
using module '..\..\modules\Helper\ObjectHelper.psm1'
using module '..\..\modules\Session.psd1'

# TODO Implement
function Compare-Messages{
    [CmdletBinding()]
    [Alias('cmm')]
    param(
        [Parameter(ValueFromPipeline=$true, Mandatory=$true)]
        $message,
        [switch]$aggregate
    )

    BEGIN {
        $_prevJson = $null
        $_prevId = $null
        $_prevAggregateState = $null
        $_currAggregateState = $null
    }
    PROCESS {
        if (-not $message.json) { continue }

        # New-provider
        switch ($message.source) {
            { $_ -in ([SOURCE]::sb, [SOURCE]::core) } {
                if ($null -ne $_prevJson) {
                    $_markets = ($_prevJson.payload.markets | Sort-Object { [int]$_.id }, { [string]$_.specifiers })
                }
                $_markets2 = ($message.json.payload.markets | Sort-Object { [int]$_.id }, { [string]$_.specifiers })
                break
            }
            ([SOURCE]::ramp) {
                if ($null -ne $_prevJson) {
                    $_markets = ($_prevJson.markets | Sort-Object { [int]$_.typeId })
                }
                $_markets2 = ($message.json.markets | Sort-Object { [int]$_.typeId })
                break
            }
            ([SOURCE]::betradar){
                if ($null -ne $_prevJson) {
                    if ($message.json.odds_change){
                        $_markets = ($_prevJson.odds_change.odds.market | Sort-Object { [int]$_.id }, { [string]$_.specifiers })
                    }
                    elseif ($message.json.bet_settlement){
                        $_markets = ($_prevJson.bet_settlement.outcomes.market | Sort-Object { [int]$_.id }, { [string]$_.specifiers })
                    }
                }
                if ($message.json.odds_change){
                    $_markets2 = ($message.json.odds_change.odds.market | Sort-Object { [int]$_.id }, { [string]$_.specifiers })
                }
                elseif ($message.json.bet_settlement){
                    $_markets2 = ($message.json.bet_settlement.outcomes.market | Sort-Object { [int]$_.id }, { [string]$_.specifiers })
                }
                break
            }
            ([SOURCE]::lsports){
                if ($null -ne $_prevJson) {
                    $_markets = ($_prevJson.markets | Sort-Object { [int]$_.id })
                }
                $_markets2 = ($message.json.Body.Events.Markets | Sort-Object { [int]$_.id })
                break
            }
            ([SOURCE]::betgenius){
                if ($null -ne $_prevJson) {
                    $_markets = ($_prevJson.markets | Sort-Object { [int]$_.id })
                }
                if ($_json.MarketSet) { $_markets2 = ($message.json.MarketSet.Markets | Sort-Object { [int]$_.id }) }
                if ($_json.ResultSet) { $_markets2 = ($message.json.ResultSet.Results | Sort-Object { [int]$_.id }) }
                break
            }
            default {
                continue
            }
        }
        $_counts = (Compare-MarketContent $_markets $_markets2 $message.source)

        $_countSame = $_counts[1]
        $_countChanged = $_counts[2]
        #$_countUnique = $_counts[3]
        $_countUnique2 = $_counts[4]

        if (-not $aggregate){
            $_item = [PSCustomObject[]]@{PSTypeName = 'MarketDiff'; id=$_prevId; id2=$message.id; total=$_markets.count; total2=$_markets2.count; `
                sameMarkets=$_countSame; changedMarkets=$_countChanged; newMarkets=$_countUnique2}
        }
        else {
            if ($null -eq $_prevAggregateState) {
                $_prevAggregateState = $_markets2
            }
            else {
                $_prevAggregateState = $_currAggregateState
            }
            $_counts2 = (Compare-MarketContent $_prevAggregateState $_markets2 $message.source)
            $_currAggregateState = ($_counts2[0] | Sort-Object { [int]$_.id }, { [string]$_.specifiers })
            $_counts2 = (Compare-MarketContent $_prevAggregateState $_currAggregateState $message.source)

            $_item = [PSCustomObject[]]@{PSTypeName = 'MarketDiff'; id=$_prevId; id2=$message.id; total=$_markets.count; total2=$_markets2.count; `
                sameMarkets=$_countSame; changedMarkets=$_countChanged; newMarkets=$_countUnique2; `
                cum_prev_total=$_prevAggregateState.count; cum_cur_total=$_currAggregateState.count; `
                cum_same=$_counts2[1]; cum_changed=$_counts2[2]; cum_new=$_counts2[4] }
        }

        if ($null -ne $_prevJson){
            Write-Output $_item
        }

        $_prevJson = $message.json
        $_prevId = $message.id
    }
    END {

    }
}