import React, { useEffect } from "react";
import { useAddStudent } from "../api/student";
import { useAddTeacher } from "../api/teacher";
import { useAddExam } from "../api/exam";

// Function to create a student object
const createExam = () => {
  const randomNum = Math.floor(Math.random() * 1000); // Generate a random number
  const fakeDate = "1970-01-01"; // Placeholder date
  const fakeDuration = "00:00"; // Placeholder duration

  const formattedDate = fakeDate;
  const formattedDuration = fakeDuration;

  return {
    registration_record_id: "",
    title: randomNum,
    exam_type_id: "1",
    subject_id: "1",
    max_grade: randomNum,
    grade_to_pass: "2",
    name: `name${randomNum}`,
    contact_information: `contact_information${randomNum}`,
    address: `address${randomNum}`,
    date: formattedDate,
    duration: formattedDuration,
    edu_class_id: 1,
    term_id: 2,
  };
};

const CreateExam = ({ number_of_user }: { number_of_user: number }) => {
  const { mutate } = useAddExam();

  useEffect(() => {
    for (let index = 0; index < number_of_user; index++) {
      const newStudent = createExam();

      // Call mutate to add the student
      mutate(newStudent);
    }
  }, [number_of_user, mutate]);

  return null; // or return some JSX if needed
};

export default CreateExam;
