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

---@class def_types.PowerOffLockedItem
---@field appname string
---@field reason string
---@field locked boolean
---@field timeout integer
local TPowerOffLockedItem = {}
TPowerOffLockedItem.__index = TPowerOffLockedItem
TPowerOffLockedItem.group = {}

local function TPowerOffLockedItem_from_obj(obj)
    return setmetatable(obj, TPowerOffLockedItem)
end

function TPowerOffLockedItem.new(appname, reason, locked, timeout)
    return TPowerOffLockedItem_from_obj({appname = appname, reason = reason, locked = locked, timeout = timeout})
end
---@param obj def_types.PowerOffLockedItem
function TPowerOffLockedItem:init_from_obj(obj)
    self.appname = obj.appname
    self.reason = obj.reason
    self.locked = obj.locked
    self.timeout = obj.timeout
end

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

TPowerOffLockedItem.from_obj = TPowerOffLockedItem_from_obj

TPowerOffLockedItem.proto_property = {'appname', 'reason', 'locked', 'timeout'}

TPowerOffLockedItem.default = {'', '', false, 0}

TPowerOffLockedItem.struct = {
    {name = 'appname', is_array = false, struct = nil}, {name = 'reason', is_array = false, struct = nil},
    {name = 'locked', is_array = false, struct = nil}, {name = 'timeout', is_array = false, struct = nil}
}

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

    validate.Optional(prefix .. 'appname', self.appname, 'string', false, errs, need_convert)
    validate.Optional(prefix .. 'reason', self.reason, 'string', false, errs, need_convert)
    validate.Optional(prefix .. 'locked', self.locked, 'bool', false, errs, need_convert)
    validate.Optional(prefix .. 'timeout', self.timeout, 'uint32', false, errs, need_convert)

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

function TPowerOffLockedItem:unpack(_)
    return self.appname, self.reason, self.locked, self.timeout
end

def_types.PowerOffLockedItem = TPowerOffLockedItem

---@class def_types.PowerOffLockedRecord
---@field key string
---@field value def_types.PowerOffLockedItem
local TPowerOffLockedRecord = {}
TPowerOffLockedRecord.__index = TPowerOffLockedRecord
TPowerOffLockedRecord.group = {}

local function TPowerOffLockedRecord_from_obj(obj)
    obj.value = utils.from_obj(def_types.PowerOffLockedItem, obj.value)
    return setmetatable(obj, TPowerOffLockedRecord)
end

function TPowerOffLockedRecord.new(dict)
    return TPowerOffLockedRecord_from_obj(dict)
end

---@param obj def_types.PowerOffLockedRecord
function TPowerOffLockedRecord:init_from_obj(obj)
    self = obj
end

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

TPowerOffLockedRecord.from_obj = TPowerOffLockedRecord_from_obj

TPowerOffLockedRecord.proto_property = {}

TPowerOffLockedRecord.default = {}

TPowerOffLockedRecord.struct = {}

function TPowerOffLockedRecord: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)

        def_types.PowerOffLockedItem.new(v.appname, v.reason, v.locked, v.timeout):validate(prefix, errs, need_convert)

    end

    TPowerOffLockedRecord:remove_error_props(errs, self)
    return self
end

function TPowerOffLockedRecord:unpack(_)
    return self
end

def_types.PowerOffLockedRecord = TPowerOffLockedRecord

---@class def_types.PwrOnLockedItem
---@field appname string
---@field reason string
---@field locked boolean
---@field timeout integer
local TPwrOnLockedItem = {}
TPwrOnLockedItem.__index = TPwrOnLockedItem
TPwrOnLockedItem.group = {}

local function TPwrOnLockedItem_from_obj(obj)
    return setmetatable(obj, TPwrOnLockedItem)
end

function TPwrOnLockedItem.new(appname, reason, locked, timeout)
    return TPwrOnLockedItem_from_obj({appname = appname, reason = reason, locked = locked, timeout = timeout})
end
---@param obj def_types.PwrOnLockedItem
function TPwrOnLockedItem:init_from_obj(obj)
    self.appname = obj.appname
    self.reason = obj.reason
    self.locked = obj.locked
    self.timeout = obj.timeout
end

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

TPwrOnLockedItem.from_obj = TPwrOnLockedItem_from_obj

TPwrOnLockedItem.proto_property = {'appname', 'reason', 'locked', 'timeout'}

TPwrOnLockedItem.default = {'', '', false, 0}

TPwrOnLockedItem.struct = {
    {name = 'appname', is_array = false, struct = nil}, {name = 'reason', is_array = false, struct = nil},
    {name = 'locked', is_array = false, struct = nil}, {name = 'timeout', is_array = false, struct = nil}
}

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

    validate.Optional(prefix .. 'appname', self.appname, 'string', false, errs, need_convert)
    validate.Optional(prefix .. 'reason', self.reason, 'string', false, errs, need_convert)
    validate.Optional(prefix .. 'locked', self.locked, 'bool', false, errs, need_convert)
    validate.Optional(prefix .. 'timeout', self.timeout, 'uint32', false, errs, need_convert)

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

function TPwrOnLockedItem:unpack(_)
    return self.appname, self.reason, self.locked, self.timeout
end

def_types.PwrOnLockedItem = TPwrOnLockedItem

---@class def_types.PwrOnLockedRecord
---@field key string
---@field value def_types.PwrOnLockedItem
local TPwrOnLockedRecord = {}
TPwrOnLockedRecord.__index = TPwrOnLockedRecord
TPwrOnLockedRecord.group = {}

local function TPwrOnLockedRecord_from_obj(obj)
    obj.value = utils.from_obj(def_types.PwrOnLockedItem, obj.value)
    return setmetatable(obj, TPwrOnLockedRecord)
end

function TPwrOnLockedRecord.new(dict)
    return TPwrOnLockedRecord_from_obj(dict)
end

---@param obj def_types.PwrOnLockedRecord
function TPwrOnLockedRecord:init_from_obj(obj)
    self = obj
end

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

TPwrOnLockedRecord.from_obj = TPwrOnLockedRecord_from_obj

TPwrOnLockedRecord.proto_property = {}

TPwrOnLockedRecord.default = {}

TPwrOnLockedRecord.struct = {}

function TPwrOnLockedRecord: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)

        def_types.PwrOnLockedItem.new(v.appname, v.reason, v.locked, v.timeout):validate(prefix, errs, need_convert)

    end

    TPwrOnLockedRecord:remove_error_props(errs, self)
    return self
end

function TPwrOnLockedRecord:unpack(_)
    return self
end

def_types.PwrOnLockedRecord = TPwrOnLockedRecord

return def_types
