import { describePolicy } from "../../utils/permissions/policy.js";
import { getPermissionProfile } from "./permissionProfiles.js";
export class PermissionService {
    policy;
    constructor(policy) {
        this.policy = policy;
    }
    toToolContext(root) {
        return {
            root,
            allowShell: this.policy.allowShell,
            allowBrowser: this.policy.allowBrowser,
        };
    }
    update(update) {
        this.policy = { ...this.policy, ...update };
        return this.snapshot();
    }
    applyProfile(name) {
        const profile = getPermissionProfile(name);
        if (!profile)
            throw new Error(`Unknown permission profile: ${name}`);
        this.policy = {
            ...this.policy,
            allowShell: profile.allowShell,
            allowBrowser: profile.allowBrowser,
        };
        return this.snapshot();
    }
    snapshot() {
        return { ...this.policy };
    }
    describe() {
        return describePolicy(this.policy);
    }
}
