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

---@class MLogicSelfTest.PeriodMs
---@field PeriodMs integer
local TPeriodMs = {}
TPeriodMs.__index = TPeriodMs
TPeriodMs.group = {}

local function TPeriodMs_from_obj(obj)
    return setmetatable(obj, TPeriodMs)
end

function TPeriodMs.new(PeriodMs)
    return TPeriodMs_from_obj({PeriodMs = PeriodMs or 6000})
end
---@param obj MLogicSelfTest.PeriodMs
function TPeriodMs:init_from_obj(obj)
    self.PeriodMs = obj.PeriodMs or 6000
end

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

TPeriodMs.from_obj = TPeriodMs_from_obj

TPeriodMs.proto_property = {'PeriodMs'}

TPeriodMs.default = {0}

TPeriodMs.struct = {{name = 'PeriodMs', is_array = false, struct = nil}}

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

    validate.Optional(prefix .. 'PeriodMs', self.PeriodMs, 'uint32', false, errs, need_convert)

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

function TPeriodMs:unpack(_)
    return self.PeriodMs
end

MLogicSelfTest.PeriodMs = TPeriodMs

---@class MLogicSelfTest.DebounceCount
---@field DebounceCount integer
local TDebounceCount = {}
TDebounceCount.__index = TDebounceCount
TDebounceCount.group = {}

local function TDebounceCount_from_obj(obj)
    return setmetatable(obj, TDebounceCount)
end

function TDebounceCount.new(DebounceCount)
    return TDebounceCount_from_obj({DebounceCount = DebounceCount or 3})
end
---@param obj MLogicSelfTest.DebounceCount
function TDebounceCount:init_from_obj(obj)
    self.DebounceCount = obj.DebounceCount or 3
end

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

TDebounceCount.from_obj = TDebounceCount_from_obj

TDebounceCount.proto_property = {'DebounceCount'}

TDebounceCount.default = {0}

TDebounceCount.struct = {{name = 'DebounceCount', is_array = false, struct = nil}}

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

    validate.Optional(prefix .. 'DebounceCount', self.DebounceCount, 'uint8', false, errs, need_convert)

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

function TDebounceCount:unpack(_)
    return self.DebounceCount
end

MLogicSelfTest.DebounceCount = TDebounceCount

---@class MLogicSelfTest.ReadVal
---@field ReadVal integer[]
local TReadVal = {}
TReadVal.__index = TReadVal
TReadVal.group = {}

local function TReadVal_from_obj(obj)
    return setmetatable(obj, TReadVal)
end

function TReadVal.new(ReadVal)
    return TReadVal_from_obj({ReadVal = ReadVal})
end
---@param obj MLogicSelfTest.ReadVal
function TReadVal:init_from_obj(obj)
    self.ReadVal = obj.ReadVal
end

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

TReadVal.from_obj = TReadVal_from_obj

TReadVal.proto_property = {'ReadVal'}

TReadVal.default = {{}}

TReadVal.struct = {{name = 'ReadVal', is_array = true, struct = nil}}

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

    validate.OptionalArray(prefix .. 'ReadVal', self.ReadVal, 'uint32', false, errs, need_convert)

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

function TReadVal:unpack(_)
    return self.ReadVal
end

MLogicSelfTest.ReadVal = TReadVal

---@class MLogicSelfTest.WriteVal
---@field WriteVal integer[]
local TWriteVal = {}
TWriteVal.__index = TWriteVal
TWriteVal.group = {}

local function TWriteVal_from_obj(obj)
    return setmetatable(obj, TWriteVal)
end

function TWriteVal.new(WriteVal)
    return TWriteVal_from_obj({WriteVal = WriteVal})
end
---@param obj MLogicSelfTest.WriteVal
function TWriteVal:init_from_obj(obj)
    self.WriteVal = obj.WriteVal
end

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

TWriteVal.from_obj = TWriteVal_from_obj

TWriteVal.proto_property = {'WriteVal'}

TWriteVal.default = {{}}

TWriteVal.struct = {{name = 'WriteVal', is_array = true, struct = nil}}

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

    validate.OptionalArray(prefix .. 'WriteVal', self.WriteVal, 'uint32', false, errs, need_convert)

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

function TWriteVal:unpack(_)
    return self.WriteVal
end

MLogicSelfTest.WriteVal = TWriteVal

---@class MLogicSelfTest.ReadReg
---@field ReadReg integer
local TReadReg = {}
TReadReg.__index = TReadReg
TReadReg.group = {}

local function TReadReg_from_obj(obj)
    return setmetatable(obj, TReadReg)
end

function TReadReg.new(ReadReg)
    return TReadReg_from_obj({ReadReg = ReadReg})
end
---@param obj MLogicSelfTest.ReadReg
function TReadReg:init_from_obj(obj)
    self.ReadReg = obj.ReadReg
end

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

TReadReg.from_obj = TReadReg_from_obj

TReadReg.proto_property = {'ReadReg'}

TReadReg.default = {0}

TReadReg.struct = {{name = 'ReadReg', is_array = false, struct = nil}}

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

    validate.Optional(prefix .. 'ReadReg', self.ReadReg, 'uint32', false, errs, need_convert)

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

function TReadReg:unpack(_)
    return self.ReadReg
end

MLogicSelfTest.ReadReg = TReadReg

---@class MLogicSelfTest.WriteReg
---@field WriteReg integer
local TWriteReg = {}
TWriteReg.__index = TWriteReg
TWriteReg.group = {}

local function TWriteReg_from_obj(obj)
    return setmetatable(obj, TWriteReg)
end

function TWriteReg.new(WriteReg)
    return TWriteReg_from_obj({WriteReg = WriteReg})
end
---@param obj MLogicSelfTest.WriteReg
function TWriteReg:init_from_obj(obj)
    self.WriteReg = obj.WriteReg
end

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

TWriteReg.from_obj = TWriteReg_from_obj

TWriteReg.proto_property = {'WriteReg'}

TWriteReg.default = {0}

TWriteReg.struct = {{name = 'WriteReg', is_array = false, struct = nil}}

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

    validate.Optional(prefix .. 'WriteReg', self.WriteReg, 'uint32', false, errs, need_convert)

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

function TWriteReg:unpack(_)
    return self.WriteReg
end

MLogicSelfTest.WriteReg = TWriteReg

---@class MLogicSelfTest.RefChip
---@field RefChip integer[]
local TRefChip = {}
TRefChip.__index = TRefChip
TRefChip.group = {}

local function TRefChip_from_obj(obj)
    return setmetatable(obj, TRefChip)
end

function TRefChip.new(RefChip)
    return TRefChip_from_obj({RefChip = RefChip})
end
---@param obj MLogicSelfTest.RefChip
function TRefChip:init_from_obj(obj)
    self.RefChip = obj.RefChip
end

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

TRefChip.from_obj = TRefChip_from_obj

TRefChip.proto_property = {'RefChip'}

TRefChip.default = {{}}

TRefChip.struct = {{name = 'RefChip', is_array = true, struct = nil}}

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

    validate.OptionalArray(prefix .. 'RefChip', self.RefChip, 'uint8', false, errs, need_convert)

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

function TRefChip:unpack(_)
    return self.RefChip
end

MLogicSelfTest.RefChip = TRefChip

return MLogicSelfTest
