-- 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 mdb = require 'mc.mdb'

local FirmwareRestore = {}

---@class FirmwareRestore.Object
---@field key string
---@field value string
local TObject = {}
TObject.__index = TObject
TObject.group = {}

local function TObject_from_obj(obj)
    return setmetatable(obj, TObject)
end

function TObject.new(dict)
    return TObject_from_obj(dict)
end

---@param obj FirmwareRestore.Object
function TObject:init_from_obj(obj)
    self = obj
end

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

TObject.from_obj = TObject_from_obj

TObject.proto_property = {}

TObject.default = {}

TObject.struct = {}

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

    for k, v in pairs(self) do

        validate.Optional(prefix .. 'key', k, 'string', false, errs, need_convert)

        validate.Optional(prefix .. 'value', v, 'string', false, errs, need_convert)

    end

    TObject:remove_error_props(errs, self)
    return self
end

function TObject:unpack(_)
    return self
end

FirmwareRestore.Object = TObject

---@class FirmwareRestore.FirmwareRestoreCheckReplyRsp
local TFirmwareRestoreCheckReplyRsp = {}
TFirmwareRestoreCheckReplyRsp.__index = TFirmwareRestoreCheckReplyRsp
TFirmwareRestoreCheckReplyRsp.group = {}

local function TFirmwareRestoreCheckReplyRsp_from_obj(obj)
    return setmetatable(obj, TFirmwareRestoreCheckReplyRsp)
end

function TFirmwareRestoreCheckReplyRsp.new()
    return TFirmwareRestoreCheckReplyRsp_from_obj({})
end
---@param obj FirmwareRestore.FirmwareRestoreCheckReplyRsp
function TFirmwareRestoreCheckReplyRsp:init_from_obj(obj)

end

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

TFirmwareRestoreCheckReplyRsp.from_obj = TFirmwareRestoreCheckReplyRsp_from_obj

TFirmwareRestoreCheckReplyRsp.proto_property = {}

TFirmwareRestoreCheckReplyRsp.default = {}

TFirmwareRestoreCheckReplyRsp.struct = {}

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

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

function TFirmwareRestoreCheckReplyRsp:unpack(_)
end

FirmwareRestore.FirmwareRestoreCheckReplyRsp = TFirmwareRestoreCheckReplyRsp

---@class FirmwareRestore.FirmwareRestoreCheckReplyReq
---@field Result integer
---@field SystemId integer
---@field FirmwareType string
---@field ComponentID integer
---@field ComponentIDEx integer
---@field AdditionalOptions FirmwareRestore.Object
local TFirmwareRestoreCheckReplyReq = {}
TFirmwareRestoreCheckReplyReq.__index = TFirmwareRestoreCheckReplyReq
TFirmwareRestoreCheckReplyReq.group = {}

local function TFirmwareRestoreCheckReplyReq_from_obj(obj)
    return setmetatable(obj, TFirmwareRestoreCheckReplyReq)
end

function TFirmwareRestoreCheckReplyReq.new(Result, SystemId, FirmwareType, ComponentID, ComponentIDEx, AdditionalOptions)
    return TFirmwareRestoreCheckReplyReq_from_obj({
        Result = Result,
        SystemId = SystemId,
        FirmwareType = FirmwareType,
        ComponentID = ComponentID,
        ComponentIDEx = ComponentIDEx,
        AdditionalOptions = AdditionalOptions
    })
end
---@param obj FirmwareRestore.FirmwareRestoreCheckReplyReq
function TFirmwareRestoreCheckReplyReq:init_from_obj(obj)
    self.Result = obj.Result
    self.SystemId = obj.SystemId
    self.FirmwareType = obj.FirmwareType
    self.ComponentID = obj.ComponentID
    self.ComponentIDEx = obj.ComponentIDEx
    self.AdditionalOptions = obj.AdditionalOptions
end

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

TFirmwareRestoreCheckReplyReq.from_obj = TFirmwareRestoreCheckReplyReq_from_obj

TFirmwareRestoreCheckReplyReq.proto_property = {
    'Result', 'SystemId', 'FirmwareType', 'ComponentID', 'ComponentIDEx', 'AdditionalOptions'
}

TFirmwareRestoreCheckReplyReq.default = {0, 0, '', 0, 0, FirmwareRestore.Object.default}

TFirmwareRestoreCheckReplyReq.struct = {
    {name = 'Result', is_array = false, struct = nil}, {name = 'SystemId', is_array = false, struct = nil},
    {name = 'FirmwareType', is_array = false, struct = nil}, {name = 'ComponentID', is_array = false, struct = nil},
    {name = 'ComponentIDEx', is_array = false, struct = nil},
    {name = 'AdditionalOptions', is_array = false, struct = FirmwareRestore.Object.struct}
}

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

    FirmwareRestore.Object.new(self.AdditionalOptions):validate(prefix, errs, need_convert)

    validate.Optional(prefix .. 'Result', self.Result, 'int32', false, errs, need_convert)
    validate.Optional(prefix .. 'SystemId', self.SystemId, 'int32', false, errs, need_convert)
    validate.Optional(prefix .. 'FirmwareType', self.FirmwareType, 'string', false, errs, need_convert)
    validate.Optional(prefix .. 'ComponentID', self.ComponentID, 'uint8', false, errs, need_convert)
    validate.Optional(prefix .. 'ComponentIDEx', self.ComponentIDEx, 'uint32', false, errs, need_convert)

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

function TFirmwareRestoreCheckReplyReq:unpack(_)
    return self.Result, self.SystemId, self.FirmwareType, self.ComponentID, self.ComponentIDEx, self.AdditionalOptions
end

FirmwareRestore.FirmwareRestoreCheckReplyReq = TFirmwareRestoreCheckReplyReq

---@class FirmwareRestore.InitiateRestoreActionRsp
local TInitiateRestoreActionRsp = {}
TInitiateRestoreActionRsp.__index = TInitiateRestoreActionRsp
TInitiateRestoreActionRsp.group = {}

local function TInitiateRestoreActionRsp_from_obj(obj)
    return setmetatable(obj, TInitiateRestoreActionRsp)
end

function TInitiateRestoreActionRsp.new()
    return TInitiateRestoreActionRsp_from_obj({})
end
---@param obj FirmwareRestore.InitiateRestoreActionRsp
function TInitiateRestoreActionRsp:init_from_obj(obj)

end

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

TInitiateRestoreActionRsp.from_obj = TInitiateRestoreActionRsp_from_obj

TInitiateRestoreActionRsp.proto_property = {}

TInitiateRestoreActionRsp.default = {}

TInitiateRestoreActionRsp.struct = {}

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

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

function TInitiateRestoreActionRsp:unpack(_)
end

FirmwareRestore.InitiateRestoreActionRsp = TInitiateRestoreActionRsp

---@class FirmwareRestore.InitiateRestoreActionReq
---@field ComponentID integer
---@field ComponentIDEx integer
---@field AdditionalOptions FirmwareRestore.Object
local TInitiateRestoreActionReq = {}
TInitiateRestoreActionReq.__index = TInitiateRestoreActionReq
TInitiateRestoreActionReq.group = {}

local function TInitiateRestoreActionReq_from_obj(obj)
    return setmetatable(obj, TInitiateRestoreActionReq)
end

function TInitiateRestoreActionReq.new(ComponentID, ComponentIDEx, AdditionalOptions)
    return TInitiateRestoreActionReq_from_obj({
        ComponentID = ComponentID,
        ComponentIDEx = ComponentIDEx,
        AdditionalOptions = AdditionalOptions
    })
end
---@param obj FirmwareRestore.InitiateRestoreActionReq
function TInitiateRestoreActionReq:init_from_obj(obj)
    self.ComponentID = obj.ComponentID
    self.ComponentIDEx = obj.ComponentIDEx
    self.AdditionalOptions = obj.AdditionalOptions
end

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

TInitiateRestoreActionReq.from_obj = TInitiateRestoreActionReq_from_obj

TInitiateRestoreActionReq.proto_property = {'ComponentID', 'ComponentIDEx', 'AdditionalOptions'}

TInitiateRestoreActionReq.default = {0, 0, FirmwareRestore.Object.default}

TInitiateRestoreActionReq.struct = {
    {name = 'ComponentID', is_array = false, struct = nil}, {name = 'ComponentIDEx', is_array = false, struct = nil},
    {name = 'AdditionalOptions', is_array = false, struct = FirmwareRestore.Object.struct}
}

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

    FirmwareRestore.Object.new(self.AdditionalOptions):validate(prefix, errs, need_convert)

    validate.Optional(prefix .. 'ComponentID', self.ComponentID, 'uint8', false, errs, need_convert)
    validate.Optional(prefix .. 'ComponentIDEx', self.ComponentIDEx, 'uint32', false, errs, need_convert)

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

function TInitiateRestoreActionReq:unpack(_)
    return self.ComponentID, self.ComponentIDEx, self.AdditionalOptions
end

FirmwareRestore.InitiateRestoreActionReq = TInitiateRestoreActionReq

FirmwareRestore.interface = mdb.register_interface('bmc.kepler.UpdateService.FirmwareRestore', {}, {
    InitiateRestoreAction = {'a{ss}yua{ss}', '', TInitiateRestoreActionReq, TInitiateRestoreActionRsp},
    FirmwareRestoreCheckReply = {'a{ss}iisyua{ss}', '', TFirmwareRestoreCheckReplyReq, TFirmwareRestoreCheckReplyRsp}
}, {})

return FirmwareRestore
