// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright 2024 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_1_0_1 : ObjectProxy {

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

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

    public static new EventLog_1_0_1 StaticCast(ObjectProxy proxy) {
      return proxy == null ? null : new EventLog_1_0_1(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 GetFirstIdResult {
      public int _ret_;
    }

    public GetFirstIdResult getFirstId() {
      JsonObject _parameters = null;
      var _result = RpcCall("getFirstId", _parameters);
      var _ret = new GetFirstIdResult();
      _ret._ret_ = (int)_result["_ret_"];
      return _ret;
    }

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

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

    public class GetLastIdResult {
      public int _ret_;
    }

    public GetLastIdResult getLastId() {
      JsonObject _parameters = null;
      var _result = RpcCall("getLastId", _parameters);
      var _ret = new GetLastIdResult();
      _ret._ret_ = (int)_result["_ret_"];
      return _ret;
    }

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

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

    public class GetEntriesResult {
      public System.Collections.Generic.IEnumerable<Com.Raritan.Idl.logging.LogEntry> entries;
    }

    public GetEntriesResult getEntries(int refId, int count, Com.Raritan.Idl.logging.RangeDirection direction) {
      var _parameters = new LightJson.JsonObject();
      _parameters["refId"] = refId;
      _parameters["count"] = count;
      _parameters["direction"] = (int)direction;

      var _result = RpcCall("getEntries", _parameters);
      var _ret = new GetEntriesResult();
      _ret.entries = new System.Collections.Generic.List<Com.Raritan.Idl.logging.LogEntry>(_result["entries"].AsJsonArray.Select(
        _value => Com.Raritan.Idl.logging.LogEntry.Decode(_value, agent)));
      return _ret;
    }

    public AsyncRequest getEntries(int refId, int count, Com.Raritan.Idl.logging.RangeDirection direction, AsyncRpcResponse<GetEntriesResult>.SuccessHandler rsp, AsyncRpcResponse.FailureHandler fail) {
      return getEntries(refId, count, direction, rsp, fail, RpcCtrl.Default);
    }

    public AsyncRequest getEntries(int refId, int count, Com.Raritan.Idl.logging.RangeDirection direction, AsyncRpcResponse<GetEntriesResult>.SuccessHandler rsp, AsyncRpcResponse.FailureHandler fail, RpcCtrl rpcCtrl) {
      var _parameters = new LightJson.JsonObject();
      try {
        _parameters["refId"] = refId;
        _parameters["count"] = count;
        _parameters["direction"] = (int)direction;
      } catch (Exception e) {
        if (fail != null) fail(e);
      }

      return RpcCall("getEntries", _parameters,
        _result => {
          try {
            var _ret = new GetEntriesResult();
            _ret.entries = new System.Collections.Generic.List<Com.Raritan.Idl.logging.LogEntry>(_result["entries"].AsJsonArray.Select(
              _value => Com.Raritan.Idl.logging.LogEntry.Decode(_value, agent)));
            rsp(_ret);
          } catch (Exception e) {
            if (fail != null) fail(e);
          }
        }, fail, rpcCtrl);
    }

    public class GetFilteredEntriesResult {
      public System.Collections.Generic.IEnumerable<Com.Raritan.Idl.logging.LogEntry> entries;
    }

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

      var _result = RpcCall("getFilteredEntries", _parameters);
      var _ret = new GetFilteredEntriesResult();
      _ret.entries = new System.Collections.Generic.List<Com.Raritan.Idl.logging.LogEntry>(_result["entries"].AsJsonArray.Select(
        _value => Com.Raritan.Idl.logging.LogEntry.Decode(_value, agent)));
      return _ret;
    }

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

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

      return RpcCall("getFilteredEntries", _parameters,
        _result => {
          try {
            var _ret = new GetFilteredEntriesResult();
            _ret.entries = new System.Collections.Generic.List<Com.Raritan.Idl.logging.LogEntry>(_result["entries"].AsJsonArray.Select(
              _value => Com.Raritan.Idl.logging.LogEntry.Decode(_value, agent)));
            rsp(_ret);
          } catch (Exception e) {
            if (fail != null) fail(e);
          }
        }, fail, rpcCtrl);
    }

  }
}
