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

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

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

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

    public const int ERR_INVALID_PARAMS = 1;

    public class GetSettingsResult {
      public System.Collections.Generic.IEnumerable<Com.Raritan.Idl.net.ServiceSettings> servicesSettings;
    }

    public GetSettingsResult getSettings() {
      JsonObject _parameters = null;
      var _result = RpcCall("getSettings", _parameters);
      var _ret = new GetSettingsResult();
      _ret.servicesSettings = new System.Collections.Generic.List<Com.Raritan.Idl.net.ServiceSettings>(_result["servicesSettings"].AsJsonArray.Select(
        _value => Com.Raritan.Idl.net.ServiceSettings.Decode(_value, agent)));
      return _ret;
    }

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

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

    public class SetSettingsResult {
      public int _ret_;
    }

    public SetSettingsResult setSettings(System.Collections.Generic.IEnumerable<Com.Raritan.Idl.net.ServiceSettings> servicesSettings) {
      var _parameters = new LightJson.JsonObject();
      _parameters["servicesSettings"] = new JsonArray(servicesSettings.Select(
        _value => (JsonValue)(_value.Encode())));

      var _result = RpcCall("setSettings", _parameters);
      var _ret = new SetSettingsResult();
      _ret._ret_ = (int)_result["_ret_"];
      return _ret;
    }

    public AsyncRequest setSettings(System.Collections.Generic.IEnumerable<Com.Raritan.Idl.net.ServiceSettings> servicesSettings, AsyncRpcResponse<SetSettingsResult>.SuccessHandler rsp, AsyncRpcResponse.FailureHandler fail) {
      return setSettings(servicesSettings, rsp, fail, RpcCtrl.Default);
    }

    public AsyncRequest setSettings(System.Collections.Generic.IEnumerable<Com.Raritan.Idl.net.ServiceSettings> servicesSettings, AsyncRpcResponse<SetSettingsResult>.SuccessHandler rsp, AsyncRpcResponse.FailureHandler fail, RpcCtrl rpcCtrl) {
      var _parameters = new LightJson.JsonObject();
      try {
        _parameters["servicesSettings"] = new JsonArray(servicesSettings.Select(
          _value => (JsonValue)(_value.Encode())));
      } catch (Exception e) {
        if (fail != null) fail(e);
      }

      return RpcCall("setSettings", _parameters,
        _result => {
          try {
            var _ret = new SetSettingsResult();
            _ret._ret_ = (int)_result["_ret_"];
            rsp(_ret);
          } catch (Exception e) {
            if (fail != null) fail(e);
          }
        }, fail, rpcCtrl);
    }

  }
}
