/** * Mentor designation — unit C5 (ARCHITECTURE §5.8.5). * * Pure: no DB, no imports from `src/db`. The only dependency is the skill-level * ladder from `./assessments` (C3), which is tested to stay in sync with the DB * enum. `mentor_ready` is a per-skill predicate, not a global title — a * volunteer can mentor one skill and not another. * * The rule (ARCHITECTURE §5.8.5): * - `mentor_ready` = `verified_level >= skill.mentor_min_level` * AND `mentor_opt_in` (the volunteer agreed to teach) * AND admin-approved. * * Expertise alone does not volunteer someone: an expert who never opted in, or * who an admin has not approved, is not mentor-ready. A shadow slot (§5.8.5) * requires a mentor who is mentor_ready for that exact skill, so this predicate * is the gate the shadow validation (C6) calls. */ import { levelRank, SKILL_LEVELS, type SkillLevel } from "./assessments"; export { SKILL_LEVELS }; export type { SkillLevel }; export interface MentorReadyInput { /** The volunteer's verified level on this skill. */ verifiedLevel: SkillLevel; /** The skill's configured minimum level to mentor (ARCHITECTURE §4.3). */ mentorMinLevel: SkillLevel; /** The volunteer agreed to teach this skill (user_skills.mentor_opt_in). */ mentorOptIn: boolean; /** An admin has approved the designation. */ adminApproved: boolean; } /** * Is this volunteer mentor-ready for one skill? Pure predicate — the data layer * and the shadow validation (C6) both call it, so the rule and the code cannot * drift. */ export function isMentorReady(input: MentorReadyInput): boolean { if (levelRank(input.verifiedLevel) < levelRank(input.mentorMinLevel)) return false; if (!input.mentorOptIn) return false; if (!input.adminApproved) return false; return true; } /** * Validate a mentor-designation payload before it is written. Returns a list of * human-readable problems (empty when valid) so the route can 400 instead of * storing an inconsistent row. */ export function validateMentorDesignation(input: { verifiedLevel: string; mentorMinLevel: string; }): string[] { const problems: string[] = []; if (!SKILL_LEVELS.includes(input.verifiedLevel as SkillLevel)) { problems.push(`verifiedLevel must be one of: ${SKILL_LEVELS.join(", ")}`); } if (!SKILL_LEVELS.includes(input.mentorMinLevel as SkillLevel)) { problems.push(`mentorMinLevel must be one of: ${SKILL_LEVELS.join(", ")}`); } return problems; }