import { getPocketBase } from '../lib/pocketbase.js';

/**
 * Returns the set of week numbers that are "frozen" for an employee —
 * weeks they have already started or completed, derived from their current_week.
 * Weeks < current_week are rendered from session_completions and must not be
 * replaced by a new curriculum version.
 */
export async function getFrozenWeeks(userId: string): Promise<Set<number>> {
  const pb = await getPocketBase();

  const records = await pb.collection('employee_curriculum_state').getFullList({
    filter: `user = "${userId}"`,
  });

  const state = records[0];
  if (!state) return new Set();

  const currentWeek = state['current_week'] as number;
  const frozen = new Set<number>();
  for (let w = 1; w < currentWeek; w++) {
    frozen.add(w);
  }
  return frozen;
}
