-- Copyright (c) 2024-2025 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 common_func = require 'common.common_func'
local mc_initiator = require 'mc.initiator'

local M = {}

--- 获取操作发起者，ctx 无 get_initiator 时返回默认值
function M.get_initiator(ctx)
    if ctx and type(ctx.get_initiator) == 'function' and common_func:has_initiator(ctx) then
        return ctx:get_initiator()
    end
    return mc_initiator.new('N/A', 'N/A', 'localhost')
end

--- 判断属性是否需要导入（Import 不设置时默认为 true，仅 Import 明确为 false 时跳过）
function M.should_import(val_json, current_val)
    if not val_json then
        return false
    end
    if val_json['Import'] == false then
        return false
    end
    local import_val = val_json['Value']
    if current_val == import_val then
        return false
    end
    return true
end

return M
