// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright 2025 Raritan Inc. All rights reserved.
//
// This file was generated by IdlC from TestUnit.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 Unit_1_0_1 : ObjectProxy {

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

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

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

    public class GetDisplaysResult {
      public System.Collections.Generic.IEnumerable<Com.Raritan.Idl.test.Display> _ret_;
    }

    public GetDisplaysResult getDisplays() {
      JsonObject _parameters = null;
      var _result = RpcCall("getDisplays", _parameters);
      var _ret = new GetDisplaysResult();
      _ret._ret_ = new System.Collections.Generic.List<Com.Raritan.Idl.test.Display>(_result["_ret_"].AsJsonArray.Select(
        _value => Com.Raritan.Idl.test.Display.StaticCast(ObjectProxy.Decode(_value, agent))));
      return _ret;
    }

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

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

    public class GetButtonStatesResult {
      public System.Collections.Generic.IEnumerable<bool> _ret_;
    }

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

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

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

    public class SetBuzzerResult {
    }

    public SetBuzzerResult setBuzzer(bool isOn) {
      var _parameters = new LightJson.JsonObject();
      _parameters["isOn"] = isOn;

      var _result = RpcCall("setBuzzer", _parameters);
      var _ret = new SetBuzzerResult();
      return _ret;
    }

    public AsyncRequest setBuzzer(bool isOn, AsyncRpcResponse<SetBuzzerResult>.SuccessHandler rsp, AsyncRpcResponse.FailureHandler fail) {
      return setBuzzer(isOn, rsp, fail, RpcCtrl.Default);
    }

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

      return RpcCall("setBuzzer", _parameters,
        _result => {
          try {
            var _ret = new SetBuzzerResult();
            rsp(_ret);
          } catch (Exception e) {
            if (fail != null) fail(e);
          }
        }, fail, rpcCtrl);
    }

    public class ResetAllSlaveControllersResult {
    }

    public ResetAllSlaveControllersResult resetAllSlaveControllers() {
      JsonObject _parameters = null;
      var _result = RpcCall("resetAllSlaveControllers", _parameters);
      var _ret = new ResetAllSlaveControllersResult();
      return _ret;
    }

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

    public AsyncRequest resetAllSlaveControllers(AsyncRpcResponse<ResetAllSlaveControllersResult>.SuccessHandler rsp, AsyncRpcResponse.FailureHandler fail, RpcCtrl rpcCtrl) {
      JsonObject _parameters = null;
      return RpcCall("resetAllSlaveControllers", _parameters,
        _result => {
          try {
            var _ret = new ResetAllSlaveControllersResult();
            rsp(_ret);
          } catch (Exception e) {
            if (fail != null) fail(e);
          }
        }, fail, rpcCtrl);
    }

    public class TriggerSlaveControllerWatchdogResult {
    }

    public TriggerSlaveControllerWatchdogResult triggerSlaveControllerWatchdog(int rs485Addr) {
      var _parameters = new LightJson.JsonObject();
      _parameters["rs485Addr"] = rs485Addr;

      var _result = RpcCall("triggerSlaveControllerWatchdog", _parameters);
      var _ret = new TriggerSlaveControllerWatchdogResult();
      return _ret;
    }

    public AsyncRequest triggerSlaveControllerWatchdog(int rs485Addr, AsyncRpcResponse<TriggerSlaveControllerWatchdogResult>.SuccessHandler rsp, AsyncRpcResponse.FailureHandler fail) {
      return triggerSlaveControllerWatchdog(rs485Addr, rsp, fail, RpcCtrl.Default);
    }

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

      return RpcCall("triggerSlaveControllerWatchdog", _parameters,
        _result => {
          try {
            var _ret = new TriggerSlaveControllerWatchdogResult();
            rsp(_ret);
          } catch (Exception e) {
            if (fail != null) fail(e);
          }
        }, fail, rpcCtrl);
    }

  }
}
