"""Canonical reader for Student.enrolled_subjects.

Standards: Rule 10 (one canonical reader per concept);
AERA/APA/NCME 2014 Std 1.0 (declared construct, not derived);
1EdTech OneRoster 1.2 (enrollment is a first-class entity);
Saltzer & Schroeder 1975 (empty = fail-safe deny);
NIST SP 800-53 SI-10 (reject invalid input at the boundary).
"""

VALID_PREFIXES = frozenset({"MT", "PH", "CH", "BI", "EN", "UR", "IS", "CS", "TQ"})


def enrolled_prefixes(student):
    """Return the set of subject prefixes the student is DECLARED in.

    Reads Student.enrolled_subjects only. No derivation. No fallback.
    Empty list means not yet declared; the caller MUST deny (fail-safe).
    """
    return set(student.enrolled_subjects or [])


def is_enrolled(student, subject_prefix):
    """True iff the student is declared in the given subject prefix."""
    if subject_prefix not in VALID_PREFIXES:
        return False
    return subject_prefix in enrolled_prefixes(student)
