-- 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.

-- Description: 电源适配层事件上报接口
local singleton = require 'mc.singleton'
local class = require 'mc.class'
local log = require 'mc.logging'
local cjson = require 'cjson'
local ctx = require 'mc.context'
local client = require 'power_mgmt.client'

local c_add_event = class()

function c_add_event.generate_switch_page_failure(assert, desc_arg1, desc_arg2)
    local param = {}
    param[#param + 1] = { 'ComponentName', 'PS' }
    param[#param + 1] = { 'State', assert }
    param[#param + 1] = { 'EventKeyId', 'PSU.PSUSwitchoverNotificationChannelFailure' }
    param[#param + 1] = { 'MessageArgs', cjson.encode({desc_arg1, desc_arg2})}
    param[#param + 1] = { 'SystemId', '' }
    param[#param + 1] = { 'ManagerId', '' }
    param[#param + 1] = { 'ChassisId', '' }
    param[#param + 1] = { 'NodeId', '' }
    local ok, ret = pcall(client.EventsEventsAddEvent, client, ctx.new(), {['SystemId'] = 1}, param)
    if ok then
        log:notice('generate_switch_page_failure successfully')
    else
        log:error('generate_switch_page_failure failed, %s', ret)
    end
end

return singleton(c_add_event)
