-- Copyright (c) 2024 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 MPowerConfiguration = {}

---@class MPowerConfiguration.MinAvailablePSUCountForUpgrade
---@field MinAvailablePSUCountForUpgrade integer
local TMinAvailablePSUCountForUpgrade = {}
TMinAvailablePSUCountForUpgrade.__index = TMinAvailablePSUCountForUpgrade
TMinAvailablePSUCountForUpgrade.group = {}

local function TMinAvailablePSUCountForUpgrade_from_obj(obj)
    return setmetatable(obj, TMinAvailablePSUCountForUpgrade)
end

function TMinAvailablePSUCountForUpgrade.new(MinAvailablePSUCountForUpgrade)
    return TMinAvailablePSUCountForUpgrade_from_obj({
        MinAvailablePSUCountForUpgrade = MinAvailablePSUCountForUpgrade or 255
    })
end
---@param obj MPowerConfiguration.MinAvailablePSUCountForUpgrade
function TMinAvailablePSUCountForUpgrade:init_from_obj(obj)
    self.MinAvailablePSUCountForUpgrade = obj.MinAvailablePSUCountForUpgrade or 255
end

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

TMinAvailablePSUCountForUpgrade.from_obj = TMinAvailablePSUCountForUpgrade_from_obj

TMinAvailablePSUCountForUpgrade.proto_property = {'MinAvailablePSUCountForUpgrade'}

TMinAvailablePSUCountForUpgrade.default = {0}

TMinAvailablePSUCountForUpgrade.struct = {{name = 'MinAvailablePSUCountForUpgrade', is_array = false, struct = nil}}

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

    validate.Optional(prefix .. 'MinAvailablePSUCountForUpgrade', self.MinAvailablePSUCountForUpgrade, 'uint8', false,
        errs, need_convert)

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

function TMinAvailablePSUCountForUpgrade:unpack(_)
    return self.MinAvailablePSUCountForUpgrade
end

MPowerConfiguration.MinAvailablePSUCountForUpgrade = TMinAvailablePSUCountForUpgrade

---@class MPowerConfiguration.Id
---@field Id integer
local TId = {}
TId.__index = TId
TId.group = {}

local function TId_from_obj(obj)
    return setmetatable(obj, TId)
end

function TId.new(Id)
    return TId_from_obj({Id = Id or 1})
end
---@param obj MPowerConfiguration.Id
function TId:init_from_obj(obj)
    self.Id = obj.Id or 1
end

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

TId.from_obj = TId_from_obj

TId.proto_property = {'Id'}

TId.default = {0}

TId.struct = {{name = 'Id', is_array = false, struct = nil}}

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

    validate.Required(prefix .. 'Id', self.Id, 'uint8', false, errs, need_convert)

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

function TId:unpack(_)
    return self.Id
end

MPowerConfiguration.Id = TId

---@class MPowerConfiguration.SinglePsuSupport
---@field SinglePsuSupport integer
local TSinglePsuSupport = {}
TSinglePsuSupport.__index = TSinglePsuSupport
TSinglePsuSupport.group = {}

local function TSinglePsuSupport_from_obj(obj)
    return setmetatable(obj, TSinglePsuSupport)
end

function TSinglePsuSupport.new(SinglePsuSupport)
    return TSinglePsuSupport_from_obj({SinglePsuSupport = SinglePsuSupport or 0})
end
---@param obj MPowerConfiguration.SinglePsuSupport
function TSinglePsuSupport:init_from_obj(obj)
    self.SinglePsuSupport = obj.SinglePsuSupport or 0
end

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

TSinglePsuSupport.from_obj = TSinglePsuSupport_from_obj

TSinglePsuSupport.proto_property = {'SinglePsuSupport'}

TSinglePsuSupport.default = {0}

TSinglePsuSupport.struct = {{name = 'SinglePsuSupport', is_array = false, struct = nil}}

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

    validate.Optional(prefix .. 'SinglePsuSupport', self.SinglePsuSupport, 'uint8', false, errs, need_convert)

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

function TSinglePsuSupport:unpack(_)
    return self.SinglePsuSupport
end

MPowerConfiguration.SinglePsuSupport = TSinglePsuSupport

return MPowerConfiguration
