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

---@class MDriveStartSlotConfig.Configurations
---@field Configurations def_types.DriveStartSlotConfigItem[]
local TConfigurations = {}
TConfigurations.__index = TConfigurations
TConfigurations.group = {}

local function TConfigurations_from_obj(obj)
    obj.Configurations = utils.from_obj(def_types.DriveStartSlotConfigItem, obj.Configurations, true)
    return setmetatable(obj, TConfigurations)
end

function TConfigurations.new(Configurations)
    return TConfigurations_from_obj({Configurations = Configurations})
end
---@param obj MDriveStartSlotConfig.Configurations
function TConfigurations:init_from_obj(obj)
    self.Configurations = obj.Configurations
end

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

TConfigurations.from_obj = TConfigurations_from_obj

TConfigurations.proto_property = {'Configurations'}

TConfigurations.default = {{}}

TConfigurations.struct = {
    {name = 'Configurations', is_array = true, struct = def_types.DriveStartSlotConfigItem.struct}
}

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

    for _, v in pairs(self.Configurations) do
        def_types.DriveStartSlotConfigItem.new(v.UID, v.Slot, v.ChildSlotType, v.ChildSlotIndex, v.ChildStartSlot):validate(
            prefix, errs, need_convert)
    end

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

function TConfigurations:unpack(raw)
    return utils.unpack(raw, self.Configurations, true)
end

MDriveStartSlotConfig.Configurations = TConfigurations

return MDriveStartSlotConfig
