// tools/assign-role-handler.ts — Handler for assign_role tool (SPEC-166)
import { assignRole } from '../storage/rbac-store.js';
import { ROLE_DESCRIPTIONS } from '../engine/rbac/index.js';
export async function handleAssignRole(args) {
    if (!args.userId || args.userId.trim().length === 0) {
        return {
            content: [{ type: 'text', text: 'userId must not be empty.' }],
            isError: true,
        };
    }
    const config = await assignRole(args.projectId, args.userId.trim(), args.role, args.specId, args.assignedBy);
    const scope = args.specId ? ` for spec "${args.specId}"` : ' at project level';
    const roleDesc = ROLE_DESCRIPTIONS[args.role];
    const assignmentCount = config.assignments.length;
    const lines = [
        `Assigned role "${args.role}"${scope} to user "${args.userId}".`,
        `Role description: ${roleDesc}`,
        `Total assignments in project: ${String(assignmentCount)}`,
    ];
    if (args.assignedBy) {
        lines.push(`Assigned by: ${args.assignedBy}`);
    }
    return { content: [{ type: 'text', text: lines.join('\n') }] };
}
//# sourceMappingURL=assign-role-handler.js.map