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

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

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

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

    public class GetDeviceFilesResult {
      public System.Collections.Generic.IEnumerable<string> _ret_;
    }

    public GetDeviceFilesResult getDeviceFiles() {
      JsonObject _parameters = null;
      var _result = RpcCall("getDeviceFiles", _parameters);
      var _ret = new GetDeviceFilesResult();
      _ret._ret_ = new System.Collections.Generic.List<string>(_result["_ret_"].AsJsonArray.Select(
        _value => (string)_value));
      return _ret;
    }

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

    public AsyncRequest getDeviceFiles(AsyncRpcResponse<GetDeviceFilesResult>.SuccessHandler rsp, AsyncRpcResponse.FailureHandler fail, RpcCtrl rpcCtrl) {
      JsonObject _parameters = null;
      return RpcCall("getDeviceFiles", _parameters,
        _result => {
          try {
            var _ret = new GetDeviceFilesResult();
            _ret._ret_ = new System.Collections.Generic.List<string>(_result["_ret_"].AsJsonArray.Select(
              _value => (string)_value));
            rsp(_ret);
          } catch (Exception e) {
            if (fail != null) fail(e);
          }
        }, fail, rpcCtrl);
    }

    public class TestLoop1Result {
      public Com.Raritan.Idl.test.Result _ret_;
    }

    public TestLoop1Result testLoop1(string devfile) {
      var _parameters = new LightJson.JsonObject();
      _parameters["devfile"] = devfile;

      var _result = RpcCall("testLoop1", _parameters);
      var _ret = new TestLoop1Result();
      _ret._ret_ = Com.Raritan.Idl.test.Result.Decode(_result["_ret_"], agent);
      return _ret;
    }

    public AsyncRequest testLoop1(string devfile, AsyncRpcResponse<TestLoop1Result>.SuccessHandler rsp, AsyncRpcResponse.FailureHandler fail) {
      return testLoop1(devfile, rsp, fail, RpcCtrl.Default);
    }

    public AsyncRequest testLoop1(string devfile, AsyncRpcResponse<TestLoop1Result>.SuccessHandler rsp, AsyncRpcResponse.FailureHandler fail, RpcCtrl rpcCtrl) {
      var _parameters = new LightJson.JsonObject();
      try {
        _parameters["devfile"] = devfile;
      } catch (Exception e) {
        if (fail != null) fail(e);
      }

      return RpcCall("testLoop1", _parameters,
        _result => {
          try {
            var _ret = new TestLoop1Result();
            _ret._ret_ = Com.Raritan.Idl.test.Result.Decode(_result["_ret_"], agent);
            rsp(_ret);
          } catch (Exception e) {
            if (fail != null) fail(e);
          }
        }, fail, rpcCtrl);
    }

    public class TestLoop2Result {
      public Com.Raritan.Idl.test.Result _ret_;
    }

    public TestLoop2Result testLoop2(string devfile) {
      var _parameters = new LightJson.JsonObject();
      _parameters["devfile"] = devfile;

      var _result = RpcCall("testLoop2", _parameters);
      var _ret = new TestLoop2Result();
      _ret._ret_ = Com.Raritan.Idl.test.Result.Decode(_result["_ret_"], agent);
      return _ret;
    }

    public AsyncRequest testLoop2(string devfile, AsyncRpcResponse<TestLoop2Result>.SuccessHandler rsp, AsyncRpcResponse.FailureHandler fail) {
      return testLoop2(devfile, rsp, fail, RpcCtrl.Default);
    }

    public AsyncRequest testLoop2(string devfile, AsyncRpcResponse<TestLoop2Result>.SuccessHandler rsp, AsyncRpcResponse.FailureHandler fail, RpcCtrl rpcCtrl) {
      var _parameters = new LightJson.JsonObject();
      try {
        _parameters["devfile"] = devfile;
      } catch (Exception e) {
        if (fail != null) fail(e);
      }

      return RpcCall("testLoop2", _parameters,
        _result => {
          try {
            var _ret = new TestLoop2Result();
            _ret._ret_ = Com.Raritan.Idl.test.Result.Decode(_result["_ret_"], agent);
            rsp(_ret);
          } catch (Exception e) {
            if (fail != null) fail(e);
          }
        }, fail, rpcCtrl);
    }

  }
}
