-- 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 utils_file = require('utils.file')

local utils = {}

function utils.route(route_file, ...)
    local route_func = dofile(os.getenv('PROJECT_DIR') .. '/' .. route_file)
    return route_func(...)
end

function utils.template(tmpl_file, ...)
    local echoes_func = dofile(os.getenv('PROJECT_DIR') .. '/' .. tmpl_file)
    print(echoes_func(...))
end

function utils.compare_file_content(file1, file2)
    local fd1 = utils_file.open_s(file1, 'r')
    if not fd1 then
        print('Empty file', fd1)
        return false
    end

    local fd2 = utils_file.open_s(file2, 'r')

    if not fd2 then
        print('Empty file', fd2)
        fd1:close()
        return false
    end

    local str1 = fd1:read('*a')
    local str2 = fd2:read('*a')
    fd1:close()
    fd2:close()

    return str1 == str2
end

return utils