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

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

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

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

    public class RebootResult {
    }

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

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

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

    public class FactoryResetResult {
    }

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

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

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

    public class GetVersionResult {
      public string _ret_;
    }

    public GetVersionResult getVersion() {
      JsonObject _parameters = null;
      var _result = RpcCall("getVersion", _parameters);
      var _ret = new GetVersionResult();
      _ret._ret_ = (string)_result["_ret_"];
      return _ret;
    }

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

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

    public class GetUpdateHistoryResult {
      public System.Collections.Generic.IEnumerable<Com.Raritan.Idl.firmware.UpdateHistoryEntry> _ret_;
    }

    public GetUpdateHistoryResult getUpdateHistory() {
      JsonObject _parameters = null;
      var _result = RpcCall("getUpdateHistory", _parameters);
      var _ret = new GetUpdateHistoryResult();
      _ret._ret_ = new System.Collections.Generic.List<Com.Raritan.Idl.firmware.UpdateHistoryEntry>(_result["_ret_"].AsJsonArray.Select(
        _value => Com.Raritan.Idl.firmware.UpdateHistoryEntry.Decode(_value, agent)));
      return _ret;
    }

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

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

    public class UpdateAvailableResult {
      public bool _ret_;
      public bool failedCheck;
      public System.DateTime lastChecked;
      public string version;
      public string url;
    }

    public UpdateAvailableResult updateAvailable() {
      JsonObject _parameters = null;
      var _result = RpcCall("updateAvailable", _parameters);
      var _ret = new UpdateAvailableResult();
      _ret._ret_ = (bool)_result["_ret_"];
      _ret.failedCheck = (bool)_result["failedCheck"];
      _ret.lastChecked = new System.DateTime(_result["lastChecked"] * System.TimeSpan.TicksPerSecond + new System.DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc).Ticks, System.DateTimeKind.Utc).ToLocalTime();
      _ret.version = (string)_result["version"];
      _ret.url = (string)_result["url"];
      return _ret;
    }

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

    public AsyncRequest updateAvailable(AsyncRpcResponse<UpdateAvailableResult>.SuccessHandler rsp, AsyncRpcResponse.FailureHandler fail, RpcCtrl rpcCtrl) {
      JsonObject _parameters = null;
      return RpcCall("updateAvailable", _parameters,
        _result => {
          try {
            var _ret = new UpdateAvailableResult();
            _ret._ret_ = (bool)_result["_ret_"];
            _ret.failedCheck = (bool)_result["failedCheck"];
            _ret.lastChecked = new System.DateTime(_result["lastChecked"] * System.TimeSpan.TicksPerSecond + new System.DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc).Ticks, System.DateTimeKind.Utc).ToLocalTime();
            _ret.version = (string)_result["version"];
            _ret.url = (string)_result["url"];
            rsp(_ret);
          } catch (Exception e) {
            if (fail != null) fail(e);
          }
        }, fail, rpcCtrl);
    }

    public class EnableOnlineCheckResult {
    }

    public EnableOnlineCheckResult enableOnlineCheck(bool enable) {
      var _parameters = new LightJson.JsonObject();
      _parameters["enable"] = enable;

      var _result = RpcCall("enableOnlineCheck", _parameters);
      var _ret = new EnableOnlineCheckResult();
      return _ret;
    }

    public AsyncRequest enableOnlineCheck(bool enable, AsyncRpcResponse<EnableOnlineCheckResult>.SuccessHandler rsp, AsyncRpcResponse.FailureHandler fail) {
      return enableOnlineCheck(enable, rsp, fail, RpcCtrl.Default);
    }

    public AsyncRequest enableOnlineCheck(bool enable, AsyncRpcResponse<EnableOnlineCheckResult>.SuccessHandler rsp, AsyncRpcResponse.FailureHandler fail, RpcCtrl rpcCtrl) {
      var _parameters = new LightJson.JsonObject();
      try {
        _parameters["enable"] = enable;
      } catch (Exception e) {
        if (fail != null) fail(e);
      }

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

    public class OnlineCheckEnabledResult {
      public bool _ret_;
    }

    public OnlineCheckEnabledResult onlineCheckEnabled() {
      JsonObject _parameters = null;
      var _result = RpcCall("onlineCheckEnabled", _parameters);
      var _ret = new OnlineCheckEnabledResult();
      _ret._ret_ = (bool)_result["_ret_"];
      return _ret;
    }

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

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

    public class PerformOnlineCheckResult {
    }

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

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

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

    public class DownloadImageResult {
      public bool _ret_;
    }

    public DownloadImageResult downloadImage(string url) {
      var _parameters = new LightJson.JsonObject();
      _parameters["url"] = url;

      var _result = RpcCall("downloadImage", _parameters);
      var _ret = new DownloadImageResult();
      _ret._ret_ = (bool)_result["_ret_"];
      return _ret;
    }

    public AsyncRequest downloadImage(string url, AsyncRpcResponse<DownloadImageResult>.SuccessHandler rsp, AsyncRpcResponse.FailureHandler fail) {
      return downloadImage(url, rsp, fail, RpcCtrl.Default);
    }

    public AsyncRequest downloadImage(string url, AsyncRpcResponse<DownloadImageResult>.SuccessHandler rsp, AsyncRpcResponse.FailureHandler fail, RpcCtrl rpcCtrl) {
      var _parameters = new LightJson.JsonObject();
      try {
        _parameters["url"] = url;
      } catch (Exception e) {
        if (fail != null) fail(e);
      }

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

    public class CancelDownloadResult {
    }

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

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

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

    public class GetImageStatusResult {
      public Com.Raritan.Idl.firmware.ImageStatus _ret_;
    }

    public GetImageStatusResult getImageStatus() {
      JsonObject _parameters = null;
      var _result = RpcCall("getImageStatus", _parameters);
      var _ret = new GetImageStatusResult();
      _ret._ret_ = Com.Raritan.Idl.firmware.ImageStatus.Decode(_result["_ret_"], agent);
      return _ret;
    }

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

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

    public class DiscardImageResult {
    }

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

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

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

    public class GetImageInfoResult {
      public bool _ret_;
      public Com.Raritan.Idl.firmware.ImageInfo_1_0_1 info;
    }

    public GetImageInfoResult getImageInfo() {
      JsonObject _parameters = null;
      var _result = RpcCall("getImageInfo", _parameters);
      var _ret = new GetImageInfoResult();
      _ret._ret_ = (bool)_result["_ret_"];
      _ret.info = Com.Raritan.Idl.firmware.ImageInfo_1_0_1.Decode(_result["info"], agent);
      return _ret;
    }

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

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

    public class StartUpdateResult {
    }

    public StartUpdateResult startUpdate(System.Collections.Generic.IEnumerable<Com.Raritan.Idl.firmware.UpdateFlags> flags) {
      var _parameters = new LightJson.JsonObject();
      _parameters["flags"] = new JsonArray(flags.Select(
        _value => (JsonValue)((int)_value)));

      var _result = RpcCall("startUpdate", _parameters);
      var _ret = new StartUpdateResult();
      return _ret;
    }

    public AsyncRequest startUpdate(System.Collections.Generic.IEnumerable<Com.Raritan.Idl.firmware.UpdateFlags> flags, AsyncRpcResponse<StartUpdateResult>.SuccessHandler rsp, AsyncRpcResponse.FailureHandler fail) {
      return startUpdate(flags, rsp, fail, RpcCtrl.Default);
    }

    public AsyncRequest startUpdate(System.Collections.Generic.IEnumerable<Com.Raritan.Idl.firmware.UpdateFlags> flags, AsyncRpcResponse<StartUpdateResult>.SuccessHandler rsp, AsyncRpcResponse.FailureHandler fail, RpcCtrl rpcCtrl) {
      var _parameters = new LightJson.JsonObject();
      try {
        _parameters["flags"] = new JsonArray(flags.Select(
          _value => (JsonValue)((int)_value)));
      } catch (Exception e) {
        if (fail != null) fail(e);
      }

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

  }
}
