import { Cours } from "../classes/cours";
import { Devoir } from "../classes/devoir";

const generateGrade = (cours: Cours, devoir: Devoir) => {
  const { etudiants_ids, group_id } = cours;
  const { id, type, noteMax } = devoir;

  return etudiants_ids.map((e) => {
    return {
      student: e,
      group_id: group_id,
      type: type,
      type_id: id,
      note: generateNote(0, noteMax),
    };
  });
};

const generateNote = (min, max) => {
  if (Math.random() < 0.2) {
    return null;
  }
  return Math.floor(Math.random() * (max - min + 1)) + min;
};

export { generateGrade };
