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

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

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

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

    public class PushEventsResult {
    }

    public PushEventsResult pushEvents(System.Collections.Generic.IEnumerable<Com.Raritan.Idl.idl.Event> events) {
      var _parameters = new LightJson.JsonObject();
      _parameters["events"] = new JsonArray(events.Select(
        _value => (JsonValue)(ValueObjectCodec.Encode(_value))));

      var _result = RpcCall("pushEvents", _parameters);
      var _ret = new PushEventsResult();
      return _ret;
    }

    public AsyncRequest pushEvents(System.Collections.Generic.IEnumerable<Com.Raritan.Idl.idl.Event> events, AsyncRpcResponse<PushEventsResult>.SuccessHandler rsp, AsyncRpcResponse.FailureHandler fail) {
      return pushEvents(events, rsp, fail, RpcCtrl.Default);
    }

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

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

  }
}
