public/Market/Read-Market.ps1

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

function Read-Market{
    [Alias('rdmr')]
    param(
        [Parameter(Mandatory=$true)]
        # Audit log source file from where the messages will be loaded.
        [SOURCE] $source,
        # Id of the searched scope.
        [string[]] $id,
        # Where the appointed marketId should be searched as:
        # * internalId - regular marketId used in the appointed source
        # * externalId - reference for the externalId, the one participated in this log from lower level
        # * typeId - used at some adapters when there is generalization of the marketId's typically as certain blueprint type.
        #
        # Default value is id.
        [SEARCH_SCOPE] $searchScope,
        # Sarch scope of internal ID's
        [string[]] $internalId,
        # Sarch scope of super ID's
        [string[]] $typeId,
        # Sarch scope of external ID's
        [string[]] $externalId,
        # Referent message time taken as baseline from where the messages will be start analyzing.
        [string] $referentTime,
        # Timeframe in which the messages will be analyzed after the referent time.
        [string] $timeSpan,
        # Switch for tracing outcomes for the Read-Market
        [switch] $odds,
        # If the tracing is requested for Outcomes, this could filter down the wanted outcomeId
        [string] $oid='*',
        # Aggregate state of the item
        [switch] $aggregate,
        # Displayed progress message
        [string] $progressMessage,
        # provide the result as native object rather than display one
        [switch] $asObject
    )

    $params = @{}

    #region Validation

    if ([Session]::activeSessions.Count -eq 0){
        Write-Error $LocalizedData.NoActiveSessionMessage
        return
    }

    if ($id -and $searchScope){
        if ($internalId -or $externalId -or $typeId) {
            Write-Error 'Ambiquous input parameters, use either id with searchScope, or one of other id''s.'
            return
        }
    }
    elseif (($internalId -and ($externalId -or $typeId)) -or ($externalId -and ($internalId -or $typeId)) -or ($typeId -and ($externalId -or $externalId))) {
        Write-Error 'Ambiquous input parameters, use only one of input id''s.'
        return
    }
    else {
        if ($internalId) {
            $id = $internalId
            $searchScope = [SEARCH_SCOPE]::internalId
            $internalId = $null
        }
        elseif ($externalId) {
            $id = $externalId
            $searchScope = [SEARCH_SCOPE]::externalId
            $externalId = $null
        }
        elseif ($typeId) {
            $id = $typeId
            $searchScope = [SEARCH_SCOPE]::typeId
            $typeId = $null
        }
    }

    #endregion

    if ($odds) {
        $_dataType = [DATATYPE]::Outcome
    }
    else{
        $_dataType = [DATATYPE]::Market
    }
    Write-Debug "Data type: $_dataType"

    if ($id) { $params.add('id', $id) }
    if ($searchScope) { $params.add('searchScope', $searchScope) }
    $params.add('dataType', $_dataType)
    $params.add('source', $source)
    if ($referentTime) { $params.add('referentTime', $referentTime) }
    if ($timeSpan) { $params.add('timeSpan', $timeSpan) }
    if ($oid) { $params.add('oid', $oid) }
    if ($aggregate) { $params.add('aggregate', $aggregate) }
    if ($progressMessage) { $params.add('progressMessage', $progressMessage) }
    if ($asObject) { $params.add('asObject', $asObject) }

    Read-RawLog @params
}