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

---@class StorageIpmiCmds.GetSlotPowerStateReq
---@field ManufacturerId integer
---@field Reserve integer
---@field DriveId integer
---@field ReadingOffset integer
---@field ReadingLength integer
local TGetSlotPowerStateReq = {}
TGetSlotPowerStateReq.__index = TGetSlotPowerStateReq
TGetSlotPowerStateReq.group = {}

local function TGetSlotPowerStateReq_from_obj(obj)
    return setmetatable(obj, TGetSlotPowerStateReq)
end

function TGetSlotPowerStateReq.new(ManufacturerId, Reserve, DriveId, ReadingOffset, ReadingLength)
    return TGetSlotPowerStateReq_from_obj({
        ManufacturerId = ManufacturerId,
        Reserve = Reserve,
        DriveId = DriveId,
        ReadingOffset = ReadingOffset,
        ReadingLength = ReadingLength
    })
end
---@param obj StorageIpmiCmds.GetSlotPowerStateReq
function TGetSlotPowerStateReq:init_from_obj(obj)
    self.ManufacturerId = obj.ManufacturerId
    self.Reserve = obj.Reserve
    self.DriveId = obj.DriveId
    self.ReadingOffset = obj.ReadingOffset
    self.ReadingLength = obj.ReadingLength
end

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

TGetSlotPowerStateReq.from_obj = TGetSlotPowerStateReq_from_obj

TGetSlotPowerStateReq.proto_property = {'ManufacturerId', 'Reserve', 'DriveId', 'ReadingOffset', 'ReadingLength'}

TGetSlotPowerStateReq.default = {0, 0, 0, 0, 0}

TGetSlotPowerStateReq.struct = {
    {name = 'ManufacturerId', is_array = false, struct = nil}, {name = 'Reserve', is_array = false, struct = nil},
    {name = 'DriveId', is_array = false, struct = nil}, {name = 'ReadingOffset', is_array = false, struct = nil},
    {name = 'ReadingLength', is_array = false, struct = nil}
}

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

    validate.Optional(prefix .. 'ManufacturerId', self.ManufacturerId, 'uint32', false, errs, need_convert)
    validate.Optional(prefix .. 'Reserve', self.Reserve, 'uint8', false, errs, need_convert)
    validate.Optional(prefix .. 'DriveId', self.DriveId, 'uint8', false, errs, need_convert)
    validate.Optional(prefix .. 'ReadingOffset', self.ReadingOffset, 'uint16', false, errs, need_convert)
    validate.Optional(prefix .. 'ReadingLength', self.ReadingLength, 'uint8', false, errs, need_convert)

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

function TGetSlotPowerStateReq:unpack(_)
    return self.ManufacturerId, self.Reserve, self.DriveId, self.ReadingOffset, self.ReadingLength
end

GetSlotPowerState.GetSlotPowerStateReq = TGetSlotPowerStateReq

---@class StorageIpmiCmds.GetSlotPowerStateRsp
---@field CompletionCode integer
---@field ManufactureId integer
---@field Reserve integer
---@field PowerState integer
local TGetSlotPowerStateRsp = {}
TGetSlotPowerStateRsp.__index = TGetSlotPowerStateRsp
TGetSlotPowerStateRsp.group = {}

local function TGetSlotPowerStateRsp_from_obj(obj)
    return setmetatable(obj, TGetSlotPowerStateRsp)
end

function TGetSlotPowerStateRsp.new(CompletionCode, ManufactureId, Reserve, PowerState)
    return TGetSlotPowerStateRsp_from_obj({
        CompletionCode = CompletionCode,
        ManufactureId = ManufactureId,
        Reserve = Reserve,
        PowerState = PowerState
    })
end
---@param obj StorageIpmiCmds.GetSlotPowerStateRsp
function TGetSlotPowerStateRsp:init_from_obj(obj)
    self.CompletionCode = obj.CompletionCode
    self.ManufactureId = obj.ManufactureId
    self.Reserve = obj.Reserve
    self.PowerState = obj.PowerState
end

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

TGetSlotPowerStateRsp.from_obj = TGetSlotPowerStateRsp_from_obj

TGetSlotPowerStateRsp.proto_property = {'CompletionCode', 'ManufactureId', 'Reserve', 'PowerState'}

TGetSlotPowerStateRsp.default = {0, 0, 0, 0}

TGetSlotPowerStateRsp.struct = {
    {name = 'CompletionCode', is_array = false, struct = nil}, {name = 'ManufactureId', is_array = false, struct = nil},
    {name = 'Reserve', is_array = false, struct = nil}, {name = 'PowerState', is_array = false, struct = nil}
}

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

    validate.Optional(prefix .. 'CompletionCode', self.CompletionCode, 'uint8', false, errs, need_convert)
    validate.Optional(prefix .. 'ManufactureId', self.ManufactureId, 'uint32', false, errs, need_convert)
    validate.Optional(prefix .. 'Reserve', self.Reserve, 'uint8', false, errs, need_convert)
    validate.Optional(prefix .. 'PowerState', self.PowerState, 'uint8', false, errs, need_convert)

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

function TGetSlotPowerStateRsp:unpack(_)
    return self.CompletionCode, self.ManufactureId, self.Reserve, self.PowerState
end

GetSlotPowerState.GetSlotPowerStateRsp = TGetSlotPowerStateRsp

return GetSlotPowerState
