export interface VisibleSchedule {
  id: number | null;
  classId: number | null;
  canViewDetails?: boolean;
}

export const isMaskedSchedule = (
  schedule: Pick<VisibleSchedule, 'id' | 'classId' | 'canViewDetails'>,
) =>
  schedule.canViewDetails === false ||
  (schedule.canViewDetails === undefined && (schedule.id === null || schedule.classId === null));

export const filterSchedulesForClass = <T extends VisibleSchedule>(
  schedules: T[],
  classId?: number,
): T[] => {
  if (classId == null) return schedules;
  return schedules.filter((schedule) => isMaskedSchedule(schedule) || schedule.classId === classId);
};
