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

    static public readonly new TypeInfo typeInfo = new TypeInfo("portsmodel.Port:2.0.4", null);

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

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

    public const int NO_ERROR = 0;

    public const int ERR_INVALID_PARAM = 1;

    public const int ERR_DEVICE_BUSY = 2;

    public enum DetectionType {
      AUTO,
      PINNED,
      DISABLED,
    }

    public enum DeviceTypeId {
      UNSPECIFIED,
      OTHER,
      SENSOR_HUB,
      BEEPER,
      ASSET_STRIP,
      POWER_CIM,
      GATEWAY_SENSOR,
    }

    public class DeviceTypeWithId : ICloneable {
      public object Clone() {
        DeviceTypeWithId copy = new DeviceTypeWithId();
        copy.id = this.id;
        copy.type = this.type;
        return copy;
      }

      public LightJson.JsonObject Encode() {
        LightJson.JsonObject json = new LightJson.JsonObject();
        json["id"] = (int)this.id;
        json["type"] = this.type;
        return json;
      }

      public static DeviceTypeWithId Decode(LightJson.JsonObject json, Agent agent) {
        DeviceTypeWithId inst = new DeviceTypeWithId();
        inst.id = (Com.Raritan.Idl.portsmodel.Port_2_0_4.DeviceTypeId)(int)json["id"];
        inst.type = (string)json["type"];
        return inst;
      }

      public Com.Raritan.Idl.portsmodel.Port_2_0_4.DeviceTypeId id = Com.Raritan.Idl.portsmodel.Port_2_0_4.DeviceTypeId.UNSPECIFIED;
      public string type = "";
    }

    public class DetectionMode : ICloneable {
      public object Clone() {
        DetectionMode copy = new DetectionMode();
        copy.type = this.type;
        copy.pinnedDeviceType = this.pinnedDeviceType;
        return copy;
      }

      public LightJson.JsonObject Encode() {
        LightJson.JsonObject json = new LightJson.JsonObject();
        json["type"] = (int)this.type;
        json["pinnedDeviceType"] = this.pinnedDeviceType;
        return json;
      }

      public static DetectionMode Decode(LightJson.JsonObject json, Agent agent) {
        DetectionMode inst = new DetectionMode();
        inst.type = (Com.Raritan.Idl.portsmodel.Port_2_0_4.DetectionType)(int)json["type"];
        inst.pinnedDeviceType = (string)json["pinnedDeviceType"];
        return inst;
      }

      public Com.Raritan.Idl.portsmodel.Port_2_0_4.DetectionType type = Com.Raritan.Idl.portsmodel.Port_2_0_4.DetectionType.AUTO;
      public string pinnedDeviceType = "";
    }

    public class Properties : ICloneable {
      public object Clone() {
        Properties copy = new Properties();
        copy.name = this.name;
        copy.label = this.label;
        copy.mode = this.mode;
        copy.detectedDeviceType = this.detectedDeviceType;
        copy.detectedDeviceName = this.detectedDeviceName;
        copy.pinnedDeviceTypeId = this.pinnedDeviceTypeId;
        copy.detectedDeviceTypeId = this.detectedDeviceTypeId;
        copy.detectableDeviceTypes = this.detectableDeviceTypes;
        copy.topoId = this.topoId;
        copy.serialId = this.serialId;
        copy.portType = this.portType;
        copy.position = this.position;
        return copy;
      }

      public LightJson.JsonObject Encode() {
        LightJson.JsonObject json = new LightJson.JsonObject();
        json["name"] = this.name;
        json["label"] = this.label;
        json["mode"] = this.mode.Encode();
        json["detectedDeviceType"] = this.detectedDeviceType;
        json["detectedDeviceName"] = this.detectedDeviceName;
        json["pinnedDeviceTypeId"] = (int)this.pinnedDeviceTypeId;
        json["detectedDeviceTypeId"] = (int)this.detectedDeviceTypeId;
        json["detectableDeviceTypes"] = new JsonArray(this.detectableDeviceTypes.Select(
          _value => (JsonValue)(_value.Encode())));
        json["topoId"] = this.topoId;
        json["serialId"] = this.serialId;
        json["portType"] = (int)this.portType;
        json["position"] = new JsonArray(this.position.Select(
          _value => (JsonValue)(_value.Encode())));
        return json;
      }

      public static Properties Decode(LightJson.JsonObject json, Agent agent) {
        Properties inst = new Properties();
        inst.name = (string)json["name"];
        inst.label = (string)json["label"];
        inst.mode = Com.Raritan.Idl.portsmodel.Port_2_0_4.DetectionMode.Decode(json["mode"], agent);
        inst.detectedDeviceType = (string)json["detectedDeviceType"];
        inst.detectedDeviceName = (string)json["detectedDeviceName"];
        inst.pinnedDeviceTypeId = (Com.Raritan.Idl.portsmodel.Port_2_0_4.DeviceTypeId)(int)json["pinnedDeviceTypeId"];
        inst.detectedDeviceTypeId = (Com.Raritan.Idl.portsmodel.Port_2_0_4.DeviceTypeId)(int)json["detectedDeviceTypeId"];
        inst.detectableDeviceTypes = new System.Collections.Generic.List<Com.Raritan.Idl.portsmodel.Port_2_0_4.DeviceTypeWithId>(json["detectableDeviceTypes"].AsJsonArray.Select(
          _value => Com.Raritan.Idl.portsmodel.Port_2_0_4.DeviceTypeWithId.Decode(_value, agent)));
        inst.topoId = (string)json["topoId"];
        inst.serialId = (string)json["serialId"];
        inst.portType = (Com.Raritan.Idl.peripheral.PortType_5_0_0)(int)json["portType"];
        inst.position = new System.Collections.Generic.List<Com.Raritan.Idl.peripheral.PosElement_5_0_0>(json["position"].AsJsonArray.Select(
          _value => Com.Raritan.Idl.peripheral.PosElement_5_0_0.Decode(_value, agent)));
        return inst;
      }

      public string name = "";
      public string label = "";
      public Com.Raritan.Idl.portsmodel.Port_2_0_4.DetectionMode mode = new Com.Raritan.Idl.portsmodel.Port_2_0_4.DetectionMode();
      public string detectedDeviceType = "";
      public string detectedDeviceName = "";
      public Com.Raritan.Idl.portsmodel.Port_2_0_4.DeviceTypeId pinnedDeviceTypeId = Com.Raritan.Idl.portsmodel.Port_2_0_4.DeviceTypeId.UNSPECIFIED;
      public Com.Raritan.Idl.portsmodel.Port_2_0_4.DeviceTypeId detectedDeviceTypeId = Com.Raritan.Idl.portsmodel.Port_2_0_4.DeviceTypeId.UNSPECIFIED;
      public System.Collections.Generic.IEnumerable<Com.Raritan.Idl.portsmodel.Port_2_0_4.DeviceTypeWithId> detectableDeviceTypes = new System.Collections.Generic.List<Com.Raritan.Idl.portsmodel.Port_2_0_4.DeviceTypeWithId>();
      public string topoId = "";
      public string serialId = "";
      public Com.Raritan.Idl.peripheral.PortType_5_0_0 portType = Com.Raritan.Idl.peripheral.PortType_5_0_0.ONBOARD;
      public System.Collections.Generic.IEnumerable<Com.Raritan.Idl.peripheral.PosElement_5_0_0> position = new System.Collections.Generic.List<Com.Raritan.Idl.peripheral.PosElement_5_0_0>();
    }

    public class PropertiesChangedEvent : Com.Raritan.Idl.idl.Event {
      static public readonly new TypeInfo typeInfo = new TypeInfo("portsmodel.Port_2_0_4.PropertiesChangedEvent:1.0.0", Com.Raritan.Idl.idl.Event.typeInfo);

      public Com.Raritan.Idl.portsmodel.Port_2_0_4.Properties oldProperties = new Com.Raritan.Idl.portsmodel.Port_2_0_4.Properties();
      public Com.Raritan.Idl.portsmodel.Port_2_0_4.Properties newProperties = new Com.Raritan.Idl.portsmodel.Port_2_0_4.Properties();
    }

    public class DeviceChangedEvent : Com.Raritan.Idl.idl.Event {
      static public readonly new TypeInfo typeInfo = new TypeInfo("portsmodel.Port_2_0_4.DeviceChangedEvent:1.0.0", Com.Raritan.Idl.idl.Event.typeInfo);

      public ObjectProxy oldDevice = null;
      public ObjectProxy newDevice = null;
    }

    public class GetPropertiesResult {
      public Com.Raritan.Idl.portsmodel.Port_2_0_4.Properties _ret_;
    }

    public GetPropertiesResult getProperties() {
      JsonObject _parameters = null;
      var _result = RpcCall("getProperties", _parameters);
      var _ret = new GetPropertiesResult();
      _ret._ret_ = Com.Raritan.Idl.portsmodel.Port_2_0_4.Properties.Decode(_result["_ret_"], agent);
      return _ret;
    }

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

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

    public class SetNameResult {
    }

    public SetNameResult setName(string name) {
      var _parameters = new LightJson.JsonObject();
      _parameters["name"] = name;

      var _result = RpcCall("setName", _parameters);
      var _ret = new SetNameResult();
      return _ret;
    }

    public AsyncRequest setName(string name, AsyncRpcResponse<SetNameResult>.SuccessHandler rsp, AsyncRpcResponse.FailureHandler fail) {
      return setName(name, rsp, fail, RpcCtrl.Default);
    }

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

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

    public class SetDetectionModeResult {
      public int _ret_;
    }

    public SetDetectionModeResult setDetectionMode(Com.Raritan.Idl.portsmodel.Port_2_0_4.DetectionMode mode) {
      var _parameters = new LightJson.JsonObject();
      _parameters["mode"] = mode.Encode();

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

    public AsyncRequest setDetectionMode(Com.Raritan.Idl.portsmodel.Port_2_0_4.DetectionMode mode, AsyncRpcResponse<SetDetectionModeResult>.SuccessHandler rsp, AsyncRpcResponse.FailureHandler fail) {
      return setDetectionMode(mode, rsp, fail, RpcCtrl.Default);
    }

    public AsyncRequest setDetectionMode(Com.Raritan.Idl.portsmodel.Port_2_0_4.DetectionMode mode, AsyncRpcResponse<SetDetectionModeResult>.SuccessHandler rsp, AsyncRpcResponse.FailureHandler fail, RpcCtrl rpcCtrl) {
      var _parameters = new LightJson.JsonObject();
      try {
        _parameters["mode"] = mode.Encode();
      } catch (Exception e) {
        if (fail != null) fail(e);
      }

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

    public class GetDetectableDevicesResult {
      public System.Collections.Generic.IEnumerable<string> _ret_;
    }

    public GetDetectableDevicesResult getDetectableDevices() {
      JsonObject _parameters = null;
      var _result = RpcCall("getDetectableDevices", _parameters);
      var _ret = new GetDetectableDevicesResult();
      _ret._ret_ = new System.Collections.Generic.List<string>(_result["_ret_"].AsJsonArray.Select(
        _value => (string)_value));
      return _ret;
    }

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

    public AsyncRequest getDetectableDevices(AsyncRpcResponse<GetDetectableDevicesResult>.SuccessHandler rsp, AsyncRpcResponse.FailureHandler fail, RpcCtrl rpcCtrl) {
      JsonObject _parameters = null;
      return RpcCall("getDetectableDevices", _parameters,
        _result => {
          try {
            var _ret = new GetDetectableDevicesResult();
            _ret._ret_ = new System.Collections.Generic.List<string>(_result["_ret_"].AsJsonArray.Select(
              _value => (string)_value));
            rsp(_ret);
          } catch (Exception e) {
            if (fail != null) fail(e);
          }
        }, fail, rpcCtrl);
    }

    public class GetDeviceResult {
      public ObjectProxy _ret_;
    }

    public GetDeviceResult getDevice() {
      JsonObject _parameters = null;
      var _result = RpcCall("getDevice", _parameters);
      var _ret = new GetDeviceResult();
      _ret._ret_ = ObjectProxy.Decode(_result["_ret_"], agent);
      return _ret;
    }

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

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

    public class GetDeviceConfigResult {
      public ObjectProxy _ret_;
    }

    public GetDeviceConfigResult getDeviceConfig(string deviceType) {
      var _parameters = new LightJson.JsonObject();
      _parameters["deviceType"] = deviceType;

      var _result = RpcCall("getDeviceConfig", _parameters);
      var _ret = new GetDeviceConfigResult();
      _ret._ret_ = ObjectProxy.Decode(_result["_ret_"], agent);
      return _ret;
    }

    public AsyncRequest getDeviceConfig(string deviceType, AsyncRpcResponse<GetDeviceConfigResult>.SuccessHandler rsp, AsyncRpcResponse.FailureHandler fail) {
      return getDeviceConfig(deviceType, rsp, fail, RpcCtrl.Default);
    }

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

      return RpcCall("getDeviceConfig", _parameters,
        _result => {
          try {
            var _ret = new GetDeviceConfigResult();
            _ret._ret_ = ObjectProxy.Decode(_result["_ret_"], agent);
            rsp(_ret);
          } catch (Exception e) {
            if (fail != null) fail(e);
          }
        }, fail, rpcCtrl);
    }

    public class GetFuseResult {
      public Com.Raritan.Idl.portsmodel.PortFuse_1_0_1 _ret_;
    }

    public GetFuseResult getFuse() {
      JsonObject _parameters = null;
      var _result = RpcCall("getFuse", _parameters);
      var _ret = new GetFuseResult();
      _ret._ret_ = Com.Raritan.Idl.portsmodel.PortFuse_1_0_1.StaticCast(ObjectProxy.Decode(_result["_ret_"], agent));
      return _ret;
    }

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

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

  }
}
