-- Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved.
--
-- this file licensed under the 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.
--
-- Author: auto generate
-- Create: 2026-2-12
-- Description: DO NOT EDIT; Code generated by "message.lua.mako"
local validate = require 'mc.validate'
local utils = require 'mc.utils'
local mdb = require 'mc.mdb'

local PCIeMock = {}

---@class PCIeMock.UnloadDeviceRsp
local TUnloadDeviceRsp = {}
TUnloadDeviceRsp.__index = TUnloadDeviceRsp
TUnloadDeviceRsp.group = {}

local function TUnloadDeviceRsp_from_obj(obj)
    return setmetatable(obj, TUnloadDeviceRsp)
end

function TUnloadDeviceRsp.new()
    return TUnloadDeviceRsp_from_obj({})
end
---@param obj PCIeMock.UnloadDeviceRsp
function TUnloadDeviceRsp:init_from_obj(obj)

end

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

TUnloadDeviceRsp.from_obj = TUnloadDeviceRsp_from_obj

TUnloadDeviceRsp.proto_property = {}

TUnloadDeviceRsp.default = {}

TUnloadDeviceRsp.struct = {}

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

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

function TUnloadDeviceRsp:unpack(_)
end

PCIeMock.UnloadDeviceRsp = TUnloadDeviceRsp

---@class PCIeMock.UnloadDeviceReq
---@field DeviceType string
---@field Slot integer
local TUnloadDeviceReq = {}
TUnloadDeviceReq.__index = TUnloadDeviceReq
TUnloadDeviceReq.group = {}

local function TUnloadDeviceReq_from_obj(obj)
    return setmetatable(obj, TUnloadDeviceReq)
end

function TUnloadDeviceReq.new(DeviceType, Slot)
    return TUnloadDeviceReq_from_obj({DeviceType = DeviceType, Slot = Slot})
end
---@param obj PCIeMock.UnloadDeviceReq
function TUnloadDeviceReq:init_from_obj(obj)
    self.DeviceType = obj.DeviceType
    self.Slot = obj.Slot
end

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

TUnloadDeviceReq.from_obj = TUnloadDeviceReq_from_obj

TUnloadDeviceReq.proto_property = {'DeviceType', 'Slot'}

TUnloadDeviceReq.default = {'', 0}

TUnloadDeviceReq.struct = {
    {name = 'DeviceType', is_array = false, struct = nil}, {name = 'Slot', is_array = false, struct = nil}
}

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

    validate.Optional(prefix .. 'DeviceType', self.DeviceType, 'string', false, errs, need_convert)
    validate.Optional(prefix .. 'Slot', self.Slot, 'uint8', false, errs, need_convert)

    if self.DeviceType ~= nil then
        validate.Enum(prefix .. 'DeviceType', self.DeviceType, '', {'OCP', 'PCIe'}, errs, need_convert)
    end

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

function TUnloadDeviceReq:unpack(_)
    return self.DeviceType, self.Slot
end

PCIeMock.UnloadDeviceReq = TUnloadDeviceReq

---@class PCIeMock.LoadDeviceRsp
local TLoadDeviceRsp = {}
TLoadDeviceRsp.__index = TLoadDeviceRsp
TLoadDeviceRsp.group = {}

local function TLoadDeviceRsp_from_obj(obj)
    return setmetatable(obj, TLoadDeviceRsp)
end

function TLoadDeviceRsp.new()
    return TLoadDeviceRsp_from_obj({})
end
---@param obj PCIeMock.LoadDeviceRsp
function TLoadDeviceRsp:init_from_obj(obj)

end

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

TLoadDeviceRsp.from_obj = TLoadDeviceRsp_from_obj

TLoadDeviceRsp.proto_property = {}

TLoadDeviceRsp.default = {}

TLoadDeviceRsp.struct = {}

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

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

function TLoadDeviceRsp:unpack(_)
end

PCIeMock.LoadDeviceRsp = TLoadDeviceRsp

---@class PCIeMock.LoadDeviceReq
---@field DeviceType string
---@field Slot integer
---@field Id string
---@field AuxId string
local TLoadDeviceReq = {}
TLoadDeviceReq.__index = TLoadDeviceReq
TLoadDeviceReq.group = {}

local function TLoadDeviceReq_from_obj(obj)
    return setmetatable(obj, TLoadDeviceReq)
end

function TLoadDeviceReq.new(DeviceType, Slot, Id, AuxId)
    return TLoadDeviceReq_from_obj({DeviceType = DeviceType, Slot = Slot, Id = Id, AuxId = AuxId})
end
---@param obj PCIeMock.LoadDeviceReq
function TLoadDeviceReq:init_from_obj(obj)
    self.DeviceType = obj.DeviceType
    self.Slot = obj.Slot
    self.Id = obj.Id
    self.AuxId = obj.AuxId
end

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

TLoadDeviceReq.from_obj = TLoadDeviceReq_from_obj

TLoadDeviceReq.proto_property = {'DeviceType', 'Slot', 'Id', 'AuxId'}

TLoadDeviceReq.default = {'', 0, '', ''}

TLoadDeviceReq.descriptions = {
    [=[Specify the device type: PCIe or OCP.]=], [=[Slot of the device.]=], [=[Id of the device.]=],
    [=[AuxId of the device.]=]
}

TLoadDeviceReq.struct = {
    {name = 'DeviceType', is_array = false, struct = nil}, {name = 'Slot', is_array = false, struct = nil},
    {name = 'Id', is_array = false, struct = nil}, {name = 'AuxId', is_array = false, struct = nil}
}

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

    validate.Optional(prefix .. 'DeviceType', self.DeviceType, 'string', false, errs, need_convert)
    validate.Optional(prefix .. 'Slot', self.Slot, 'uint8', false, errs, need_convert)
    validate.Optional(prefix .. 'Id', self.Id, 'string', false, errs, need_convert)
    validate.Optional(prefix .. 'AuxId', self.AuxId, 'string', false, errs, need_convert)

    if self.DeviceType ~= nil then
        validate.Enum(prefix .. 'DeviceType', self.DeviceType, '', {'OCP', 'PCIe'}, errs, need_convert)
    end

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

function TLoadDeviceReq:unpack(_)
    return self.DeviceType, self.Slot, self.Id, self.AuxId
end

PCIeMock.LoadDeviceReq = TLoadDeviceReq

---@class PCIeMock.GetConnectorsReq
---@field DeviceType string
local TGetConnectorsReq = {}
TGetConnectorsReq.__index = TGetConnectorsReq
TGetConnectorsReq.group = {}

local function TGetConnectorsReq_from_obj(obj)
    return setmetatable(obj, TGetConnectorsReq)
end

function TGetConnectorsReq.new(DeviceType)
    return TGetConnectorsReq_from_obj({DeviceType = DeviceType})
end
---@param obj PCIeMock.GetConnectorsReq
function TGetConnectorsReq:init_from_obj(obj)
    self.DeviceType = obj.DeviceType
end

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

TGetConnectorsReq.from_obj = TGetConnectorsReq_from_obj

TGetConnectorsReq.proto_property = {'DeviceType'}

TGetConnectorsReq.default = {''}

TGetConnectorsReq.descriptions = {[=[Specify the device type: PCIe or OCP.]=]}

TGetConnectorsReq.struct = {{name = 'DeviceType', is_array = false, struct = nil}}

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

    validate.Optional(prefix .. 'DeviceType', self.DeviceType, 'string', false, errs, need_convert)

    if self.DeviceType ~= nil then
        validate.Enum(prefix .. 'DeviceType', self.DeviceType, '', {'OCP', 'PCIe'}, errs, need_convert)
    end

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

function TGetConnectorsReq:unpack(_)
    return self.DeviceType
end

PCIeMock.GetConnectorsReq = TGetConnectorsReq

---@class PCIeMock.ConnectorItem
---@field SlotNumber integer
---@field Presence string
---@field Name string
---@field Id string
---@field AuxId string
local TConnectorItem = {}
TConnectorItem.__index = TConnectorItem
TConnectorItem.group = {}

local function TConnectorItem_from_obj(obj)
    return setmetatable(obj, TConnectorItem)
end

function TConnectorItem.new(SlotNumber, Presence, Name, Id, AuxId)
    return TConnectorItem_from_obj({SlotNumber = SlotNumber, Presence = Presence, Name = Name, Id = Id, AuxId = AuxId})
end
---@param obj PCIeMock.ConnectorItem
function TConnectorItem:init_from_obj(obj)
    self.SlotNumber = obj.SlotNumber
    self.Presence = obj.Presence
    self.Name = obj.Name
    self.Id = obj.Id
    self.AuxId = obj.AuxId
end

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

TConnectorItem.from_obj = TConnectorItem_from_obj

TConnectorItem.proto_property = {'SlotNumber', 'Presence', 'Name', 'Id', 'AuxId'}

TConnectorItem.default = {0, '', '', '', ''}

TConnectorItem.struct = {
    {name = 'SlotNumber', is_array = false, struct = nil}, {name = 'Presence', is_array = false, struct = nil},
    {name = 'Name', is_array = false, struct = nil}, {name = 'Id', is_array = false, struct = nil},
    {name = 'AuxId', is_array = false, struct = nil}
}

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

    validate.Optional(prefix .. 'SlotNumber', self.SlotNumber, 'uint8', false, errs, need_convert)
    validate.Optional(prefix .. 'Presence', self.Presence, 'string', false, errs, need_convert)
    validate.Optional(prefix .. 'Name', self.Name, 'string', false, errs, need_convert)
    validate.Optional(prefix .. 'Id', self.Id, 'string', false, errs, need_convert)
    validate.Optional(prefix .. 'AuxId', self.AuxId, 'string', false, errs, need_convert)

    if self.Presence ~= nil then
        validate.Enum(prefix .. 'Presence', self.Presence, '', {'Absent', 'Present'}, errs, need_convert)
    end

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

function TConnectorItem:unpack(_)
    return self.SlotNumber, self.Presence, self.Name, self.Id, self.AuxId
end

PCIeMock.ConnectorItem = TConnectorItem

---@class PCIeMock.GetConnectorsRsp
---@field Connectors PCIeMock.ConnectorItem[]
local TGetConnectorsRsp = {}
TGetConnectorsRsp.__index = TGetConnectorsRsp
TGetConnectorsRsp.group = {}

local function TGetConnectorsRsp_from_obj(obj)
    obj.Connectors = utils.from_obj(PCIeMock.ConnectorItem, obj.Connectors, true)
    return setmetatable(obj, TGetConnectorsRsp)
end

function TGetConnectorsRsp.new(Connectors)
    return TGetConnectorsRsp_from_obj({Connectors = Connectors})
end
---@param obj PCIeMock.GetConnectorsRsp
function TGetConnectorsRsp:init_from_obj(obj)
    self.Connectors = obj.Connectors
end

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

TGetConnectorsRsp.from_obj = TGetConnectorsRsp_from_obj

TGetConnectorsRsp.proto_property = {'Connectors'}

TGetConnectorsRsp.default = {{}}

TGetConnectorsRsp.struct = {{name = 'Connectors', is_array = true, struct = PCIeMock.ConnectorItem.struct}}

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

    for _, v in pairs(self.Connectors) do
        PCIeMock.ConnectorItem.new(v.SlotNumber, v.Presence, v.Name, v.Id, v.AuxId):validate(prefix, errs, need_convert)
    end

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

function TGetConnectorsRsp:unpack(raw)
    return utils.unpack(raw, self.Connectors, true)
end

PCIeMock.GetConnectorsRsp = TGetConnectorsRsp

PCIeMock.interface = mdb.register_interface('bmc.kepler.Debug.PCIeMock', {}, {
    GetConnectors = {
        'a{ss}s', 'a(yssss)', TGetConnectorsReq, TGetConnectorsRsp,
        [=[Display the slot number and presence status of the specified device.]=]
    },
    LoadDevice = {'a{ss}syss', '', TLoadDeviceReq, TLoadDeviceRsp, [=[Simulate loading PCIe device.]=]},
    UnloadDevice = {'a{ss}sy', '', TUnloadDeviceReq, TUnloadDeviceRsp}
}, {})

return PCIeMock
