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

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

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

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

    public const int ERR_INVALID_KEY = 1;

    public const int ERR_INVALID_VALUE = 2;

    public const int ERR_NOT_ALLOWED_IN_FIPS_MODE = 3;

    public class GetValuesResult {
      public int _ret_;
      public System.Collections.Generic.IEnumerable<string> values;
    }

    public GetValuesResult getValues(System.Collections.Generic.IEnumerable<string> keys) {
      var _parameters = new LightJson.JsonObject();
      _parameters["keys"] = new JsonArray(keys.Select(
        _value => (JsonValue)(_value)));

      var _result = RpcCall("getValues", _parameters);
      var _ret = new GetValuesResult();
      _ret._ret_ = (int)_result["_ret_"];
      _ret.values = new System.Collections.Generic.List<string>(_result["values"].AsJsonArray.Select(
        _value => (string)_value));
      return _ret;
    }

    public AsyncRequest getValues(System.Collections.Generic.IEnumerable<string> keys, AsyncRpcResponse<GetValuesResult>.SuccessHandler rsp, AsyncRpcResponse.FailureHandler fail) {
      return getValues(keys, rsp, fail, RpcCtrl.Default);
    }

    public AsyncRequest getValues(System.Collections.Generic.IEnumerable<string> keys, AsyncRpcResponse<GetValuesResult>.SuccessHandler rsp, AsyncRpcResponse.FailureHandler fail, RpcCtrl rpcCtrl) {
      var _parameters = new LightJson.JsonObject();
      try {
        _parameters["keys"] = new JsonArray(keys.Select(
          _value => (JsonValue)(_value)));
      } catch (Exception e) {
        if (fail != null) fail(e);
      }

      return RpcCall("getValues", _parameters,
        _result => {
          try {
            var _ret = new GetValuesResult();
            _ret._ret_ = (int)_result["_ret_"];
            _ret.values = new System.Collections.Generic.List<string>(_result["values"].AsJsonArray.Select(
              _value => (string)_value));
            rsp(_ret);
          } catch (Exception e) {
            if (fail != null) fail(e);
          }
        }, fail, rpcCtrl);
    }

    public class SetValuesResult {
      public int _ret_;
    }

    public SetValuesResult setValues(System.Collections.Generic.IEnumerable<Com.Raritan.Idl.cfg.KeyValue> keyvaluepairs) {
      var _parameters = new LightJson.JsonObject();
      _parameters["keyvaluepairs"] = new JsonArray(keyvaluepairs.Select(
        _value => (JsonValue)(_value.Encode())));

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

    public AsyncRequest setValues(System.Collections.Generic.IEnumerable<Com.Raritan.Idl.cfg.KeyValue> keyvaluepairs, AsyncRpcResponse<SetValuesResult>.SuccessHandler rsp, AsyncRpcResponse.FailureHandler fail) {
      return setValues(keyvaluepairs, rsp, fail, RpcCtrl.Default);
    }

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

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

  }
}
