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

---@class PortConfig.NodeId
---@field NodeId string
local TNodeId = {}
TNodeId.__index = TNodeId
TNodeId.group = {}

local function TNodeId_from_obj(obj)
    return setmetatable(obj, TNodeId)
end

function TNodeId.new(NodeId)
    return TNodeId_from_obj({NodeId = NodeId})
end
---@param obj PortConfig.NodeId
function TNodeId:init_from_obj(obj)
    self.NodeId = obj.NodeId
end

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

TNodeId.from_obj = TNodeId_from_obj

TNodeId.proto_property = {'NodeId'}

TNodeId.default = {''}

TNodeId.struct = {{name = 'NodeId', is_array = false, struct = nil}}

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

    validate.Required(prefix .. 'NodeId', self.NodeId, 'string', true, errs, need_convert)

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

function TNodeId:unpack(_)
    return self.NodeId
end

PortConfig.NodeId = TNodeId

---@class PortConfig.PortCountAllowableValues
---@field PortCountAllowableValues integer[]
local TPortCountAllowableValues = {}
TPortCountAllowableValues.__index = TPortCountAllowableValues
TPortCountAllowableValues.group = {}

local function TPortCountAllowableValues_from_obj(obj)
    return setmetatable(obj, TPortCountAllowableValues)
end

function TPortCountAllowableValues.new(PortCountAllowableValues)
    return TPortCountAllowableValues_from_obj({PortCountAllowableValues = PortCountAllowableValues})
end
---@param obj PortConfig.PortCountAllowableValues
function TPortCountAllowableValues:init_from_obj(obj)
    self.PortCountAllowableValues = obj.PortCountAllowableValues
end

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

TPortCountAllowableValues.from_obj = TPortCountAllowableValues_from_obj

TPortCountAllowableValues.proto_property = {'PortCountAllowableValues'}

TPortCountAllowableValues.default = {{}}

TPortCountAllowableValues.struct = {{name = 'PortCountAllowableValues', is_array = true, struct = nil}}

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

    validate.OptionalArray(prefix .. 'PortCountAllowableValues', self.PortCountAllowableValues, 'uint8', true, errs,
        need_convert)

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

function TPortCountAllowableValues:unpack(_)
    return self.PortCountAllowableValues
end

PortConfig.PortCountAllowableValues = TPortCountAllowableValues

---@class PortConfig.PortCount
---@field PortCount integer
local TPortCount = {}
TPortCount.__index = TPortCount
TPortCount.group = {}

local function TPortCount_from_obj(obj)
    return setmetatable(obj, TPortCount)
end

function TPortCount.new(PortCount)
    return TPortCount_from_obj({PortCount = PortCount})
end
---@param obj PortConfig.PortCount
function TPortCount:init_from_obj(obj)
    self.PortCount = obj.PortCount
end

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

TPortCount.from_obj = TPortCount_from_obj

TPortCount.proto_property = {'PortCount'}

TPortCount.default = {0}

TPortCount.struct = {{name = 'PortCount', is_array = false, struct = nil}}

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

    validate.Optional(prefix .. 'PortCount', self.PortCount, 'uint8', true, errs, need_convert)

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

function TPortCount:unpack(_)
    return self.PortCount
end

PortConfig.PortCount = TPortCount

---@class PortConfig.SetPortCountRsp
local TSetPortCountRsp = {}
TSetPortCountRsp.__index = TSetPortCountRsp
TSetPortCountRsp.group = {}

local function TSetPortCountRsp_from_obj(obj)
    return setmetatable(obj, TSetPortCountRsp)
end

function TSetPortCountRsp.new()
    return TSetPortCountRsp_from_obj({})
end
---@param obj PortConfig.SetPortCountRsp
function TSetPortCountRsp:init_from_obj(obj)

end

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

TSetPortCountRsp.from_obj = TSetPortCountRsp_from_obj

TSetPortCountRsp.proto_property = {}

TSetPortCountRsp.default = {}

TSetPortCountRsp.struct = {}

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

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

function TSetPortCountRsp:unpack(_)
end

PortConfig.SetPortCountRsp = TSetPortCountRsp

---@class PortConfig.SetPortCountReq
---@field PortCount integer
local TSetPortCountReq = {}
TSetPortCountReq.__index = TSetPortCountReq
TSetPortCountReq.group = {}

local function TSetPortCountReq_from_obj(obj)
    return setmetatable(obj, TSetPortCountReq)
end

function TSetPortCountReq.new(PortCount)
    return TSetPortCountReq_from_obj({PortCount = PortCount})
end
---@param obj PortConfig.SetPortCountReq
function TSetPortCountReq:init_from_obj(obj)
    self.PortCount = obj.PortCount
end

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

TSetPortCountReq.from_obj = TSetPortCountReq_from_obj

TSetPortCountReq.proto_property = {'PortCount'}

TSetPortCountReq.default = {0}

TSetPortCountReq.struct = {{name = 'PortCount', is_array = false, struct = nil}}

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

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

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

function TSetPortCountReq:unpack(_)
    return self.PortCount
end

PortConfig.SetPortCountReq = TSetPortCountReq

PortConfig.interface = mdb.register_interface('bmc.kepler.Systems.NetworkAdapter.PortConfig', {
    PortCount = {'y', {'EMIT_CHANGE'}, true, nil},
    PortCountAllowableValues = {'ay', {}, true, nil},
    NodeId = {'s', {}, true, nil}
}, {SetPortCount = {'a{ss}y', '', TSetPortCountReq, TSetPortCountRsp}}, {})

return PortConfig
