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

    static public readonly new TypeInfo typeInfo = new TypeInfo("logging.EventLog:2.0.0", null);

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

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

    public class ClearResult {
    }

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

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

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

    public class GetInfoResult {
      public Com.Raritan.Idl.logging.LogInfo _ret_;
    }

    public GetInfoResult getInfo() {
      JsonObject _parameters = null;
      var _result = RpcCall("getInfo", _parameters);
      var _ret = new GetInfoResult();
      _ret._ret_ = Com.Raritan.Idl.logging.LogInfo.Decode(_result["_ret_"], agent);
      return _ret;
    }

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

    public AsyncRequest getInfo(AsyncRpcResponse<GetInfoResult>.SuccessHandler rsp, AsyncRpcResponse.FailureHandler fail, RpcCtrl rpcCtrl) {
      JsonObject _parameters = null;
      return RpcCall("getInfo", _parameters,
        _result => {
          try {
            var _ret = new GetInfoResult();
            _ret._ret_ = Com.Raritan.Idl.logging.LogInfo.Decode(_result["_ret_"], agent);
            rsp(_ret);
          } catch (Exception e) {
            if (fail != null) fail(e);
          }
        }, fail, rpcCtrl);
    }

    public class GetChunkResult {
      public Com.Raritan.Idl.logging.LogChunk _ret_;
    }

    public GetChunkResult getChunk(int refId, int count, Com.Raritan.Idl.logging.RangeDirection direction, System.Collections.Generic.IEnumerable<string> categories) {
      var _parameters = new LightJson.JsonObject();
      _parameters["refId"] = refId;
      _parameters["count"] = count;
      _parameters["direction"] = (int)direction;
      _parameters["categories"] = new JsonArray(categories.Select(
        _value => (JsonValue)(_value)));

      var _result = RpcCall("getChunk", _parameters);
      var _ret = new GetChunkResult();
      _ret._ret_ = Com.Raritan.Idl.logging.LogChunk.Decode(_result["_ret_"], agent);
      return _ret;
    }

    public AsyncRequest getChunk(int refId, int count, Com.Raritan.Idl.logging.RangeDirection direction, System.Collections.Generic.IEnumerable<string> categories, AsyncRpcResponse<GetChunkResult>.SuccessHandler rsp, AsyncRpcResponse.FailureHandler fail) {
      return getChunk(refId, count, direction, categories, rsp, fail, RpcCtrl.Default);
    }

    public AsyncRequest getChunk(int refId, int count, Com.Raritan.Idl.logging.RangeDirection direction, System.Collections.Generic.IEnumerable<string> categories, AsyncRpcResponse<GetChunkResult>.SuccessHandler rsp, AsyncRpcResponse.FailureHandler fail, RpcCtrl rpcCtrl) {
      var _parameters = new LightJson.JsonObject();
      try {
        _parameters["refId"] = refId;
        _parameters["count"] = count;
        _parameters["direction"] = (int)direction;
        _parameters["categories"] = new JsonArray(categories.Select(
          _value => (JsonValue)(_value)));
      } catch (Exception e) {
        if (fail != null) fail(e);
      }

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

  }
}
