"""Read the verified 2024-25 grade profile used by historical public analyses.

The JSON records grade slots in ODE's source workbooks, including suppressed,
unavailable and no-test rows. Assessment CSVs omit some of those rows. Never
infer absence of an upper grade from absence of a usable test result.
Keep this file with the downloadable analysis scripts; the JSON belongs in
<data-dir>/school_grade_profiles_2024-25.json alongside the assessment data.
"""
import hashlib,json
from pathlib import Path
FILENAME='school_grade_profiles_2024-25.json'
APPROVED_SHA256='798b6609a7464ceb3e0870dea65f94cf00b1b6ed7e95cbf7cfcceaba047367af'
CORRECTION='Grade-profile correction: 2026-11-06'
def load_profile(data_dir: Path):
    path=Path(data_dir)/FILENAME
    content=path.read_bytes()
    if hashlib.sha256(content).hexdigest()!=APPROVED_SHA256:raise ValueError('Unapproved historical grade-profile SHA-256')
    payload=json.loads(content)
    if payload['academic_year']!='2024-2025':raise ValueError('Wrong grade-profile year')
    keys=[s['key'] for s in payload['schools']]
    if len(keys)!=len(set(keys)):raise ValueError('Duplicate grade-profile school key')
    return payload

def grade_sets(data_dir: Path):
    return {s['key']:set(s['grades']) for s in load_profile(data_dir)['schools']}
