-- Copyright (c) 2026 Huawei Technologies Co., Ltd.
-- openUBMC is licensed under Mulan PSL v2.
-- You can use this software according to the terms and conditions of the Mulan PSL v2.
-- You may obtain a copy of Mulan PSL v2 at:
--          http://license.coscl.org.cn/MulanPSL2
-- THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
-- EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
-- MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
-- See the Mulan PSL v2 for more details.
local validate = require 'mc.validate'
local utils = require 'mc.utils'

local def_types = require 'class.types.types'

local MAdcVoltageConfig = {}

---@class MAdcVoltageConfig.ThresholdConfig
---@field ThresholdConfig def_types.ThresholdConfigMap[]
local TThresholdConfig = {}
TThresholdConfig.__index = TThresholdConfig
TThresholdConfig.group = {}

local function TThresholdConfig_from_obj(obj)
    obj.ThresholdConfig = utils.from_obj(def_types.ThresholdConfigMap, obj.ThresholdConfig, true)
    return setmetatable(obj, TThresholdConfig)
end

function TThresholdConfig.new(ThresholdConfig)
    return TThresholdConfig_from_obj({ThresholdConfig = ThresholdConfig})
end
---@param obj MAdcVoltageConfig.ThresholdConfig
function TThresholdConfig:init_from_obj(obj)
    self.ThresholdConfig = obj.ThresholdConfig
end

function TThresholdConfig:remove_error_props(errs, obj)
    utils.remove_obj_error_property(obj, errs, TThresholdConfig.group)
end

TThresholdConfig.from_obj = TThresholdConfig_from_obj

TThresholdConfig.proto_property = {'ThresholdConfig'}

TThresholdConfig.default = {{}}

TThresholdConfig.struct = {{name = 'ThresholdConfig', is_array = true, struct = def_types.ThresholdConfigMap.struct}}

function TThresholdConfig:validate(prefix, errs, need_convert)
    prefix = prefix or ''

    for _, v in pairs(self.ThresholdConfig) do
        def_types.ThresholdConfigMap.new(v.NodeId, v.Low, v.High):validate(prefix, errs, need_convert)
    end

    TThresholdConfig:remove_error_props(errs, self)
    validate.CheckUnknowProperty(self, TThresholdConfig.proto_property, errs, need_convert)
    return self
end

function TThresholdConfig:unpack(raw)
    return utils.unpack(raw, self.ThresholdConfig, true)
end

MAdcVoltageConfig.ThresholdConfig = TThresholdConfig

---@class MAdcVoltageConfig.ChannelRegMap
---@field ChannelRegMap integer[]
local TChannelRegMap = {}
TChannelRegMap.__index = TChannelRegMap
TChannelRegMap.group = {}

local function TChannelRegMap_from_obj(obj)
    return setmetatable(obj, TChannelRegMap)
end

function TChannelRegMap.new(ChannelRegMap)
    return TChannelRegMap_from_obj({ChannelRegMap = ChannelRegMap})
end
---@param obj MAdcVoltageConfig.ChannelRegMap
function TChannelRegMap:init_from_obj(obj)
    self.ChannelRegMap = obj.ChannelRegMap
end

function TChannelRegMap:remove_error_props(errs, obj)
    utils.remove_obj_error_property(obj, errs, TChannelRegMap.group)
end

TChannelRegMap.from_obj = TChannelRegMap_from_obj

TChannelRegMap.proto_property = {'ChannelRegMap'}

TChannelRegMap.default = {{}}

TChannelRegMap.struct = {{name = 'ChannelRegMap', is_array = true, struct = nil}}

function TChannelRegMap:validate(prefix, errs, need_convert)
    prefix = prefix or ''

    validate.OptionalArray(prefix .. 'ChannelRegMap', self.ChannelRegMap, 'uint16', false, errs, need_convert)

    TChannelRegMap:remove_error_props(errs, self)
    validate.CheckUnknowProperty(self, TChannelRegMap.proto_property, errs, need_convert)
    return self
end

function TChannelRegMap:unpack(_)
    return self.ChannelRegMap
end

MAdcVoltageConfig.ChannelRegMap = TChannelRegMap

---@class MAdcVoltageConfig.ChannelReg
---@field ChannelReg integer
local TChannelReg = {}
TChannelReg.__index = TChannelReg
TChannelReg.group = {}

local function TChannelReg_from_obj(obj)
    return setmetatable(obj, TChannelReg)
end

function TChannelReg.new(ChannelReg)
    return TChannelReg_from_obj({ChannelReg = ChannelReg or 0})
end
---@param obj MAdcVoltageConfig.ChannelReg
function TChannelReg:init_from_obj(obj)
    self.ChannelReg = obj.ChannelReg or 0
end

function TChannelReg:remove_error_props(errs, obj)
    utils.remove_obj_error_property(obj, errs, TChannelReg.group)
end

TChannelReg.from_obj = TChannelReg_from_obj

TChannelReg.proto_property = {'ChannelReg'}

TChannelReg.default = {0}

TChannelReg.struct = {{name = 'ChannelReg', is_array = false, struct = nil}}

function TChannelReg:validate(prefix, errs, need_convert)
    prefix = prefix or ''

    validate.Optional(prefix .. 'ChannelReg', self.ChannelReg, 'uint16', false, errs, need_convert)

    TChannelReg:remove_error_props(errs, self)
    validate.CheckUnknowProperty(self, TChannelReg.proto_property, errs, need_convert)
    return self
end

function TChannelReg:unpack(_)
    return self.ChannelReg
end

MAdcVoltageConfig.ChannelReg = TChannelReg

---@class MAdcVoltageConfig.ModelConfig
---@field ModelConfig integer
local TModelConfig = {}
TModelConfig.__index = TModelConfig
TModelConfig.group = {}

local function TModelConfig_from_obj(obj)
    return setmetatable(obj, TModelConfig)
end

function TModelConfig.new(ModelConfig)
    return TModelConfig_from_obj({ModelConfig = ModelConfig or 0})
end
---@param obj MAdcVoltageConfig.ModelConfig
function TModelConfig:init_from_obj(obj)
    self.ModelConfig = obj.ModelConfig or 0
end

function TModelConfig:remove_error_props(errs, obj)
    utils.remove_obj_error_property(obj, errs, TModelConfig.group)
end

TModelConfig.from_obj = TModelConfig_from_obj

TModelConfig.proto_property = {'ModelConfig'}

TModelConfig.default = {0}

TModelConfig.struct = {{name = 'ModelConfig', is_array = false, struct = nil}}

function TModelConfig:validate(prefix, errs, need_convert)
    prefix = prefix or ''

    validate.Optional(prefix .. 'ModelConfig', self.ModelConfig, 'uint16', false, errs, need_convert)

    TModelConfig:remove_error_props(errs, self)
    validate.CheckUnknowProperty(self, TModelConfig.proto_property, errs, need_convert)
    return self
end

function TModelConfig:unpack(_)
    return self.ModelConfig
end

MAdcVoltageConfig.ModelConfig = TModelConfig

---@class MAdcVoltageConfig.Model
---@field Model integer
local TModel = {}
TModel.__index = TModel
TModel.group = {}

local function TModel_from_obj(obj)
    return setmetatable(obj, TModel)
end

function TModel.new(Model)
    return TModel_from_obj({Model = Model or 0})
end
---@param obj MAdcVoltageConfig.Model
function TModel:init_from_obj(obj)
    self.Model = obj.Model or 0
end

function TModel:remove_error_props(errs, obj)
    utils.remove_obj_error_property(obj, errs, TModel.group)
end

TModel.from_obj = TModel_from_obj

TModel.proto_property = {'Model'}

TModel.default = {0}

TModel.struct = {{name = 'Model', is_array = false, struct = nil}}

function TModel:validate(prefix, errs, need_convert)
    prefix = prefix or ''

    validate.Optional(prefix .. 'Model', self.Model, 'uint16', false, errs, need_convert)

    TModel:remove_error_props(errs, self)
    validate.CheckUnknowProperty(self, TModel.proto_property, errs, need_convert)
    return self
end

function TModel:unpack(_)
    return self.Model
end

MAdcVoltageConfig.Model = TModel

---@class MAdcVoltageConfig.Voltage
---@field Voltage integer
local TVoltage = {}
TVoltage.__index = TVoltage
TVoltage.group = {}

local function TVoltage_from_obj(obj)
    return setmetatable(obj, TVoltage)
end

function TVoltage.new(Voltage)
    return TVoltage_from_obj({Voltage = Voltage or 0})
end
---@param obj MAdcVoltageConfig.Voltage
function TVoltage:init_from_obj(obj)
    self.Voltage = obj.Voltage or 0
end

function TVoltage:remove_error_props(errs, obj)
    utils.remove_obj_error_property(obj, errs, TVoltage.group)
end

TVoltage.from_obj = TVoltage_from_obj

TVoltage.proto_property = {'Voltage'}

TVoltage.default = {0}

TVoltage.struct = {{name = 'Voltage', is_array = false, struct = nil}}

function TVoltage:validate(prefix, errs, need_convert)
    prefix = prefix or ''

    validate.Optional(prefix .. 'Voltage', self.Voltage, 'uint32', false, errs, need_convert)

    TVoltage:remove_error_props(errs, self)
    validate.CheckUnknowProperty(self, TVoltage.proto_property, errs, need_convert)
    return self
end

function TVoltage:unpack(_)
    return self.Voltage
end

MAdcVoltageConfig.Voltage = TVoltage

return MAdcVoltageConfig
