// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright 2023 Raritan Inc. All rights reserved.
//
// This file was generated by IdlC from GatewaySensorManager.idl.

using System;
using System.Linq;
using LightJson;
using Com.Raritan.Idl;
using Com.Raritan.JsonRpc;
using Com.Raritan.Util;

#pragma warning disable 0108, 0219, 0414, 1591

namespace Com.Raritan.JsonRpc.peripheral.GatewaySensorManager_2_0_0 {
  public class RemoteModbusDevice_ValObjCodec : Com.Raritan.JsonRpc.peripheral.GatewaySensorManager_2_0_0.RemoteDevice_ValObjCodec {

    public static new void Register() {
      ValueObjectCodec.RegisterCodec(Com.Raritan.Idl.peripheral.GatewaySensorManager_2_0_0.RemoteModbusDevice.typeInfo, new RemoteModbusDevice_ValObjCodec());
    }

    public override void EncodeValObj(LightJson.JsonObject json, ValueObject vo) {
      base.EncodeValObj(json, vo);
      var inst = (Com.Raritan.Idl.peripheral.GatewaySensorManager_2_0_0.RemoteModbusDevice)vo;
      json["detectionIdentifiers"] = new JsonArray(inst.detectionIdentifiers.Select(_entry => (JsonValue) new JsonObject(new System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<string, LightJson.JsonValue>> {
        new System.Collections.Generic.KeyValuePair<string, JsonValue>("key", _entry.Key),
        new System.Collections.Generic.KeyValuePair<string, JsonValue>("value", _entry.Value)
      })));
      json["unitId"] = inst.unitId;
    }

    public override ValueObject DecodeValObj(ValueObject vo, LightJson.JsonObject json, Agent agent) {
      Com.Raritan.Idl.peripheral.GatewaySensorManager_2_0_0.RemoteModbusDevice inst;
      if (vo == null) {
        inst = new Com.Raritan.Idl.peripheral.GatewaySensorManager_2_0_0.RemoteModbusDevice();
      } else {
        inst = (Com.Raritan.Idl.peripheral.GatewaySensorManager_2_0_0.RemoteModbusDevice)vo;
      }
      base.DecodeValObj(vo, json, agent);
      inst.detectionIdentifiers = DictionaryHelper.Create(json["detectionIdentifiers"].AsJsonArray.Select(
        _value => new System.Collections.Generic.KeyValuePair<int, string>(_value["key"], (string)_value["value"])));
      inst.unitId = (int)json["unitId"];
      return inst;
    }

  }
}
