/**
 * Pure function: given a category (or null) and the user's default-permission
 * settings, return the decision. `null` / missing settings collapse to "ask"
 * so the caller prompts the user.
 */
export function decidePermission(category, defaultPermissions) {
    if (!category || !defaultPermissions)
        return "ask";
    const policy = defaultPermissions[category];
    if (policy === "allow")
        return "allow";
    if (policy === "deny")
        return "deny";
    return "ask";
}
/**
 * Bound policy that holds a live `getDefaultPermissions` accessor (so mid-session
 * policy changes in storage are picked up immediately) and delegates to a
 * provider-supplied tool-name → category categorizer.
 */
export class ToolPermissionPolicy {
    categorize;
    getDefaultPermissions;
    constructor(categorize, getDefaultPermissions) {
        this.categorize = categorize;
        this.getDefaultPermissions = getDefaultPermissions;
    }
    /** Get the category the adapter would assign to this tool name. */
    categoryFor(toolName) {
        return this.categorize(toolName);
    }
    /** Final decision for a given tool name. */
    decide(toolName) {
        const category = this.categorize(toolName);
        const decision = decidePermission(category, this.getDefaultPermissions());
        return { decision, category };
    }
}
