-- Use this file for functions that can be called from other mods
-- Make sure the functions are well defended against wrong input and
-- document them on the readme, what they do, what types and values
-- they expect as parameters and what types and values they return.
-- If you ever change those, consider adding backwards compatibility,
-- since other mods may rely on them.
function yl_survey.some_api_call(target, message, color)

    if (type(target) ~= "string") then
        return false, yl_survey.t("error_not_a_string", "target")
    end
    if (minetest.get_player_by_name(target) == nil) then
        return false, yl_survey.t("error_player_not_online", target)
    end

    if (type(message) ~= "string") then
        return false, yl_survey.t("error_not_a_string", "message")
    end

    -- is_color(color) does not exist, you need to implement it if you want to use it
    if (is_color(color) == false) then
        return false, yl_survey.t("error_not_a_colorspec", "color")
    end

    if (minetest.colorize == nil) then
        return false, yl_survey.t("error_function_not_available",
                                    "minetest.colorize")
    end

    local message_with_color = minetest.colorize(color, message)
    minetest.chat_send_player(target, message_with_color)

    return true, yl_survey.t("api_sent_x_to_y", message_with_color, target)
end
