local dnf = require("dnf")
assert(dnf.api_version == "dnf/v1", "requires dnf/v1")
assert(dnf.hooks.catalog()["chat.message"], "chat message Hook is unavailable")

local blocked = dnf.config.blocked_phrases or {}
assert(type(blocked) == "table", "blocked_phrases must be a string-key set")
for phrase, enabled in pairs(blocked) do
    assert(type(phrase) == "string" and #phrase > 0 and #phrase <= 128
        and type(enabled) == "boolean", "use nonempty phrases up to 128 bytes and boolean values")
end

dnf.hooks.transform("chat.message", function(ctx, plan, event)
    -- Bare, decoded chat snapshot. Plain substring search, not a Lua pattern.
    for phrase, enabled in pairs(blocked) do
        if enabled and string.find(event.text, phrase, 1, true) then
            return { allowed = false }
        end
    end
    return nil
end)
