#!/bin/bash
set -eu
source "./custom/defines.sh"

for ((portNum=0; portNum<(count); portNum++)); do
    dynamic_config_name=config_${portNum}.json
    dynamic_config="${dynamic_config_dir}/${dynamic_config_name}"

    if [[ ! -f ${dynamic_config} ]]; then
        exit 2
    fi

    jq \
        '
        .
        | if (type=="object") then
                .
            else
                "Config is not a json object." | halt_error(1)
            end
        | if (has("HdcpMode")) then
                .
            else
                "Missing \"HdcpMode\" key." | halt_error(1)
            end
        | if (.HdcpMode|type=="boolean") then
                .
            else
                "The \"HdcpMode\" key value must be of type boolean." | halt_error(1)
            end
        | if (has("LaneMode")) then
                .
            else
                "Missing \"LaneMode\" key." | halt_error(1)
            end
        | if (.LaneMode|type=="string") then
                .
            else
                "The \"LaneMode\" key value must be of type string." | halt_error(1)
            end
        ' \
        "${dynamic_config}" 2>&1
done