-- 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 = {}

---@class def_types.ThresholdConfigMap
---@field NodeId integer
---@field Low integer
---@field High integer
local TThresholdConfigMap = {}
TThresholdConfigMap.__index = TThresholdConfigMap
TThresholdConfigMap.group = {}

local function TThresholdConfigMap_from_obj(obj)
    return setmetatable(obj, TThresholdConfigMap)
end

function TThresholdConfigMap.new(NodeId, Low, High)
    return TThresholdConfigMap_from_obj({NodeId = NodeId, Low = Low, High = High})
end
---@param obj def_types.ThresholdConfigMap
function TThresholdConfigMap:init_from_obj(obj)
    self.NodeId = obj.NodeId
    self.Low = obj.Low
    self.High = obj.High
end

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

TThresholdConfigMap.from_obj = TThresholdConfigMap_from_obj

TThresholdConfigMap.proto_property = {'NodeId', 'Low', 'High'}

TThresholdConfigMap.default = {0, 0, 0}

TThresholdConfigMap.struct = {
    {name = 'NodeId', is_array = false, struct = nil}, {name = 'Low', is_array = false, struct = nil},
    {name = 'High', is_array = false, struct = nil}
}

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

    validate.Optional(prefix .. 'NodeId', self.NodeId, 'uint8', false, errs, need_convert)
    validate.Optional(prefix .. 'Low', self.Low, 'uint16', false, errs, need_convert)
    validate.Optional(prefix .. 'High', self.High, 'uint16', false, errs, need_convert)

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

function TThresholdConfigMap:unpack(_)
    return self.NodeId, self.Low, self.High
end

def_types.ThresholdConfigMap = TThresholdConfigMap

return def_types
