// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright 2020 Raritan Inc. All rights reserved.
//
// This file was generated by IdlC from Usb.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.Idl.usb {
  public class Usb : ObjectProxy {

    static public readonly new TypeInfo typeInfo = new TypeInfo("usb.Usb:1.0.0", null);

    public Usb(Agent agent, string rid, TypeInfo ti) : base(agent, rid, ti) {}
    public Usb(Agent agent, string rid) : this(agent, rid, typeInfo) {}

    public static new Usb StaticCast(ObjectProxy proxy) {
      return proxy == null ? null : new Usb(proxy.Agent, proxy.Rid, proxy.StaticTypeInfo);
    }

    public class GetDevicesResult {
      public System.Collections.Generic.IEnumerable<Com.Raritan.Idl.usb.UsbDevice> usbDevices;
    }

    public GetDevicesResult getDevices() {
      JsonObject _parameters = null;
      var _result = RpcCall("getDevices", _parameters);
      var _ret = new GetDevicesResult();
      _ret.usbDevices = new System.Collections.Generic.List<Com.Raritan.Idl.usb.UsbDevice>(_result["usbDevices"].AsJsonArray.Select(
        _value => Com.Raritan.Idl.usb.UsbDevice.Decode(_value, agent)));
      return _ret;
    }

    public AsyncRequest getDevices(AsyncRpcResponse<GetDevicesResult>.SuccessHandler rsp, AsyncRpcResponse.FailureHandler fail) {
      return getDevices(rsp, fail, RpcCtrl.Default);
    }

    public AsyncRequest getDevices(AsyncRpcResponse<GetDevicesResult>.SuccessHandler rsp, AsyncRpcResponse.FailureHandler fail, RpcCtrl rpcCtrl) {
      JsonObject _parameters = null;
      return RpcCall("getDevices", _parameters,
        _result => {
          try {
            var _ret = new GetDevicesResult();
            _ret.usbDevices = new System.Collections.Generic.List<Com.Raritan.Idl.usb.UsbDevice>(_result["usbDevices"].AsJsonArray.Select(
              _value => Com.Raritan.Idl.usb.UsbDevice.Decode(_value, agent)));
            rsp(_ret);
          } catch (Exception e) {
            if (fail != null) fail(e);
          }
        }, fail, rpcCtrl);
    }

  }
}
