const db = require('../models');
const Users = db.users;

const ActivityLogs = db.activity_logs;

const AssignmentSubmissions = db.assignment_submissions;

const Assignments = db.assignments;

const Bills = db.bills;

const ClassMessages = db.class_messages;

const ClassSubjects = db.class_subjects;

const Classes = db.classes;

const ExamSubjects = db.exam_subjects;

const Exams = db.exams;

const FeePayments = db.fee_payments;

const FeeStructures = db.fee_structures;

const LessonPlans = db.lesson_plans;

const LoginLogs = db.login_logs;

const Marks = db.marks;

const Messages = db.messages;

const Parents = db.parents;

const PeriodSettings = db.period_settings;

const SchoolAdmins = db.school_admins;

const StudentAttendance = db.student_attendance;

const Students = db.students;

const Subjects = db.subjects;

const TeacherAttendance = db.teacher_attendance;

const Teachers = db.teachers;

const Timetables = db.timetables;

const Schools = db.schools;

const ActivityLogsData = [
  {
    // type code here for "relation_one" field

    action: 'Created new school',

    entity_type: 'schools',

    entity_id: 1,

    timestamp: new Date('2023-10-01T08:30:00Z'),

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    action: 'Updated timetable',

    entity_type: 'timetables',

    entity_id: 2,

    timestamp: new Date('2023-10-01T09:30:00Z'),

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    action: 'Submitted lesson plan',

    entity_type: 'lesson_plans',

    entity_id: 3,

    timestamp: new Date('2023-10-01T10:30:00Z'),

    // type code here for "relation_one" field
  },
];

const AssignmentSubmissionsData = [
  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    submission_date: new Date('2023-10-09'),

    content: 'Completed all problems.',

    grade: 95,

    feedback: 'Excellent work!',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    submission_date: new Date('2023-10-11'),

    content: 'Detailed report submitted.',

    grade: 88,

    feedback: 'Good effort.',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    submission_date: new Date('2023-10-14'),

    content: 'Well-researched essay.',

    grade: 92,

    feedback: 'Great analysis.',

    // type code here for "relation_one" field
  },
];

const AssignmentsData = [
  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    title: 'Algebra Homework',

    description: 'Solve the given algebra problems.',

    due_date: new Date('2023-10-10'),

    attachment_url: 'http://example.com/algebra.pdf',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    title: 'Physics Lab Report',

    description: 'Complete the lab report on motion.',

    due_date: new Date('2023-10-12'),

    attachment_url: 'http://example.com/physics.pdf',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    title: 'Essay on WWII',

    description: 'Write an essay on the causes of WWII.',

    due_date: new Date('2023-10-15'),

    attachment_url: 'http://example.com/history.pdf',

    // type code here for "relation_one" field
  },
];

const BillsData = [
  {
    // type code here for "relation_one" field

    title: 'Electricity Bill',

    amount: 500,

    bill_month: 'September',

    category: 'Utilities',

    upload_url: 'http://example.com/bill1.pdf',

    status: 'pending',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    title: 'Water Bill',

    amount: 300,

    bill_month: 'September',

    category: 'Utilities',

    upload_url: 'http://example.com/bill2.pdf',

    status: 'paid',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    title: 'Internet Bill',

    amount: 200,

    bill_month: 'September',

    category: 'Utilities',

    upload_url: 'http://example.com/bill3.pdf',

    status: 'paid',

    // type code here for "relation_one" field
  },
];

const ClassMessagesData = [
  {
    // type code here for "relation_one" field

    content: 'Class test on Monday.',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    content: 'Lab session on Tuesday.',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    content: 'Field trip on Wednesday.',

    // type code here for "relation_one" field
  },
];

const ClassSubjectsData = [
  {
    // type code here for "relation_one" field
    // type code here for "relation_one" field
    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field
    // type code here for "relation_one" field
    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field
    // type code here for "relation_one" field
    // type code here for "relation_one" field
  },
];

const ClassesData = [
  {
    // type code here for "relation_one" field

    name: '10A',

    section: 'A',

    // type code here for "relation_one" field

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    name: '9B',

    section: 'B',

    // type code here for "relation_one" field

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    name: '8C',

    section: 'C',

    // type code here for "relation_one" field

    // type code here for "relation_one" field
  },
];

const ExamSubjectsData = [
  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    exam_date: new Date('2023-11-02'),

    max_marks: 100,

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    exam_date: new Date('2023-12-02'),

    max_marks: 100,

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    exam_date: new Date('2023-10-16'),

    max_marks: 100,

    // type code here for "relation_one" field
  },
];

const ExamsData = [
  {
    // type code here for "relation_one" field

    title: 'Midterm Exams',

    start_date: new Date('2023-11-01'),

    end_date: new Date('2023-11-10'),

    term: 'Fall',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    title: 'Final Exams',

    start_date: new Date('2023-12-01'),

    end_date: new Date('2023-12-15'),

    term: 'Winter',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    title: 'Quarterly Exams',

    start_date: new Date('2023-10-15'),

    end_date: new Date('2023-10-25'),

    term: 'Spring',

    // type code here for "relation_one" field
  },
];

const FeePaymentsData = [
  {
    // type code here for "relation_one" field

    amount_paid: 1500,

    payment_date: new Date('2023-09-01'),

    receipt_url: 'http://example.com/receipt1.pdf',

    term: 'Fall',

    status: 'completed',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    amount_paid: 1600,

    payment_date: new Date('2023-09-05'),

    receipt_url: 'http://example.com/receipt2.pdf',

    term: 'Winter',

    status: 'failed',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    amount_paid: 1400,

    payment_date: new Date('2023-09-10'),

    receipt_url: 'http://example.com/receipt3.pdf',

    term: 'Spring',

    status: 'pending',

    // type code here for "relation_one" field
  },
];

const FeeStructuresData = [
  {
    // type code here for "relation_one" field

    term: 'Fall',

    amount: 1500,

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    term: 'Winter',

    amount: 1600,

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    term: 'Spring',

    amount: 1400,

    // type code here for "relation_one" field
  },
];

const LessonPlansData = [
  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    week_start_date: new Date('2023-10-02'),

    plan_content: 'Algebra and Geometry',

    status: 'approved',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    week_start_date: new Date('2023-10-02'),

    plan_content: 'Physics and Chemistry',

    status: 'approved',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    week_start_date: new Date('2023-10-02'),

    plan_content: 'World War II',

    status: 'approved',

    // type code here for "relation_one" field
  },
];

const LoginLogsData = [
  {
    // type code here for "relation_one" field

    login_time: new Date('2023-10-01T08:00:00Z'),

    ip_address: '192.168.1.1',

    device_info: 'Chrome on Windows',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    login_time: new Date('2023-10-01T09:00:00Z'),

    ip_address: '192.168.1.2',

    device_info: 'Firefox on MacOS',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    login_time: new Date('2023-10-01T10:00:00Z'),

    ip_address: '192.168.1.3',

    device_info: 'Safari on iOS',

    // type code here for "relation_one" field
  },
];

const MarksData = [
  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    marks_obtained: 95,

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    marks_obtained: 88,

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    marks_obtained: 92,

    // type code here for "relation_one" field
  },
];

const MessagesData = [
  {
    // type code here for "relation_one" field

    receiver_role: 'parent',

    // type code here for "relation_one" field

    // type code here for "relation_one" field

    message_type: 'text',

    content: 'Please complete your homework by tomorrow.',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    receiver_role: 'school_admin',

    // type code here for "relation_one" field

    // type code here for "relation_one" field

    message_type: 'announcement',

    content: 'Science fair is scheduled for next week.',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    receiver_role: 'parent',

    // type code here for "relation_one" field

    // type code here for "relation_one" field

    message_type: 'text',

    content: 'History project deadline is approaching.',

    // type code here for "relation_one" field
  },
];

const ParentsData = [
  {
    // type code here for "relation_one" field

    full_name: 'Nancy Brown',

    phone_number: '555-7890',

    address: '123 Elm St, Springfield',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    full_name: 'Peter White',

    phone_number: '555-8901',

    address: '456 Oak St, Riverside',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    full_name: 'Rachel Black',

    phone_number: '555-9012',

    address: '789 Pine St, Greenwood',

    // type code here for "relation_one" field
  },
];

const PeriodSettingsData = [
  {
    // type code here for "relation_one" field

    total_periods_per_day: 8,

    period_duration: 45,

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    total_periods_per_day: 7,

    period_duration: 50,

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    total_periods_per_day: 6,

    period_duration: 55,

    // type code here for "relation_one" field
  },
];

const SchoolAdminsData = [
  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    full_name: 'John Doe',

    phone_number: '555-9876',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    full_name: 'Jane Smith',

    phone_number: '555-6543',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    full_name: 'Emily Johnson',

    phone_number: '555-3210',

    // type code here for "relation_one" field
  },
];

const StudentAttendanceData = [
  {
    // type code here for "relation_one" field

    date: new Date('2023-10-01'),

    status: 'late',

    // type code here for "relation_one" field

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    date: new Date('2023-10-01'),

    status: 'absent',

    // type code here for "relation_one" field

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    date: new Date('2023-10-01'),

    status: 'late',

    // type code here for "relation_one" field

    // type code here for "relation_one" field
  },
];

const StudentsData = [
  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    full_name: 'Tom Brown',

    dob: new Date('2005-05-15'),

    gender: 'other',

    admission_date: new Date('2020-09-01'),

    // type code here for "relation_one" field

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    full_name: 'Lucy White',

    dob: new Date('2006-06-20'),

    gender: 'female',

    admission_date: new Date('2021-09-01'),

    // type code here for "relation_one" field

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    full_name: 'Jack Black',

    dob: new Date('2007-07-25'),

    gender: 'other',

    admission_date: new Date('2019-09-01'),

    // type code here for "relation_one" field

    // type code here for "relation_one" field
  },
];

const SubjectsData = [
  {
    // type code here for "relation_one" field

    name: 'Mathematics',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    name: 'Science',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    name: 'History',

    // type code here for "relation_one" field
  },
];

const TeacherAttendanceData = [
  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    date: new Date('2023-10-01'),

    status: 'absent',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    date: new Date('2023-10-01'),

    status: 'present',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    date: new Date('2023-10-01'),

    status: 'late',

    // type code here for "relation_one" field
  },
];

const TeachersData = [
  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    full_name: 'Alice Green',

    subject_specialization: 'Mathematics',

    phone_number: '555-2345',

    joining_date: new Date('2022-08-15'),

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    full_name: 'Bob White',

    subject_specialization: 'Science',

    phone_number: '555-3456',

    joining_date: new Date('2021-09-01'),

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    full_name: 'Charlie Black',

    subject_specialization: 'History',

    phone_number: '555-4567',

    joining_date: new Date('2020-10-10'),

    // type code here for "relation_one" field
  },
];

const TimetablesData = [
  {
    day_of_week: 'Monday',

    period_number: 1,

    // type code here for "relation_one" field

    // type code here for "relation_one" field

    // type code here for "relation_one" field
  },

  {
    day_of_week: 'Sunday',

    period_number: 2,

    // type code here for "relation_one" field

    // type code here for "relation_one" field

    // type code here for "relation_one" field
  },

  {
    day_of_week: 'Thursday',

    period_number: 3,

    // type code here for "relation_one" field

    // type code here for "relation_one" field

    // type code here for "relation_one" field
  },
];

const SchoolsData = [
  {
    name: 'Springfield High',
  },

  {
    name: 'Riverside Academy',
  },

  {
    name: 'Greenwood School',
  },
];

// Similar logic for "relation_many"

async function associateUserWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const User0 = await Users.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (User0?.setSchool) {
    await User0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const User1 = await Users.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (User1?.setSchool) {
    await User1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const User2 = await Users.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (User2?.setSchool) {
    await User2.setSchool(relatedSchool2);
  }
}

async function associateActivityLogWithUser() {
  const relatedUser0 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const ActivityLog0 = await ActivityLogs.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (ActivityLog0?.setUser) {
    await ActivityLog0.setUser(relatedUser0);
  }

  const relatedUser1 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const ActivityLog1 = await ActivityLogs.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (ActivityLog1?.setUser) {
    await ActivityLog1.setUser(relatedUser1);
  }

  const relatedUser2 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const ActivityLog2 = await ActivityLogs.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (ActivityLog2?.setUser) {
    await ActivityLog2.setUser(relatedUser2);
  }
}

async function associateActivityLogWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const ActivityLog0 = await ActivityLogs.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (ActivityLog0?.setSchool) {
    await ActivityLog0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const ActivityLog1 = await ActivityLogs.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (ActivityLog1?.setSchool) {
    await ActivityLog1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const ActivityLog2 = await ActivityLogs.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (ActivityLog2?.setSchool) {
    await ActivityLog2.setSchool(relatedSchool2);
  }
}

async function associateAssignmentSubmissionWithAssignment() {
  const relatedAssignment0 = await Assignments.findOne({
    offset: Math.floor(Math.random() * (await Assignments.count())),
  });
  const AssignmentSubmission0 = await AssignmentSubmissions.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (AssignmentSubmission0?.setAssignment) {
    await AssignmentSubmission0.setAssignment(relatedAssignment0);
  }

  const relatedAssignment1 = await Assignments.findOne({
    offset: Math.floor(Math.random() * (await Assignments.count())),
  });
  const AssignmentSubmission1 = await AssignmentSubmissions.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (AssignmentSubmission1?.setAssignment) {
    await AssignmentSubmission1.setAssignment(relatedAssignment1);
  }

  const relatedAssignment2 = await Assignments.findOne({
    offset: Math.floor(Math.random() * (await Assignments.count())),
  });
  const AssignmentSubmission2 = await AssignmentSubmissions.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (AssignmentSubmission2?.setAssignment) {
    await AssignmentSubmission2.setAssignment(relatedAssignment2);
  }
}

async function associateAssignmentSubmissionWithStudent() {
  const relatedStudent0 = await Students.findOne({
    offset: Math.floor(Math.random() * (await Students.count())),
  });
  const AssignmentSubmission0 = await AssignmentSubmissions.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (AssignmentSubmission0?.setStudent) {
    await AssignmentSubmission0.setStudent(relatedStudent0);
  }

  const relatedStudent1 = await Students.findOne({
    offset: Math.floor(Math.random() * (await Students.count())),
  });
  const AssignmentSubmission1 = await AssignmentSubmissions.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (AssignmentSubmission1?.setStudent) {
    await AssignmentSubmission1.setStudent(relatedStudent1);
  }

  const relatedStudent2 = await Students.findOne({
    offset: Math.floor(Math.random() * (await Students.count())),
  });
  const AssignmentSubmission2 = await AssignmentSubmissions.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (AssignmentSubmission2?.setStudent) {
    await AssignmentSubmission2.setStudent(relatedStudent2);
  }
}

async function associateAssignmentSubmissionWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const AssignmentSubmission0 = await AssignmentSubmissions.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (AssignmentSubmission0?.setSchool) {
    await AssignmentSubmission0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const AssignmentSubmission1 = await AssignmentSubmissions.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (AssignmentSubmission1?.setSchool) {
    await AssignmentSubmission1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const AssignmentSubmission2 = await AssignmentSubmissions.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (AssignmentSubmission2?.setSchool) {
    await AssignmentSubmission2.setSchool(relatedSchool2);
  }
}

async function associateAssignmentWithTeacher() {
  const relatedTeacher0 = await Teachers.findOne({
    offset: Math.floor(Math.random() * (await Teachers.count())),
  });
  const Assignment0 = await Assignments.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Assignment0?.setTeacher) {
    await Assignment0.setTeacher(relatedTeacher0);
  }

  const relatedTeacher1 = await Teachers.findOne({
    offset: Math.floor(Math.random() * (await Teachers.count())),
  });
  const Assignment1 = await Assignments.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Assignment1?.setTeacher) {
    await Assignment1.setTeacher(relatedTeacher1);
  }

  const relatedTeacher2 = await Teachers.findOne({
    offset: Math.floor(Math.random() * (await Teachers.count())),
  });
  const Assignment2 = await Assignments.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Assignment2?.setTeacher) {
    await Assignment2.setTeacher(relatedTeacher2);
  }
}

async function associateAssignmentWithSubject() {
  const relatedSubject0 = await Subjects.findOne({
    offset: Math.floor(Math.random() * (await Subjects.count())),
  });
  const Assignment0 = await Assignments.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Assignment0?.setSubject) {
    await Assignment0.setSubject(relatedSubject0);
  }

  const relatedSubject1 = await Subjects.findOne({
    offset: Math.floor(Math.random() * (await Subjects.count())),
  });
  const Assignment1 = await Assignments.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Assignment1?.setSubject) {
    await Assignment1.setSubject(relatedSubject1);
  }

  const relatedSubject2 = await Subjects.findOne({
    offset: Math.floor(Math.random() * (await Subjects.count())),
  });
  const Assignment2 = await Assignments.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Assignment2?.setSubject) {
    await Assignment2.setSubject(relatedSubject2);
  }
}

async function associateAssignmentWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Assignment0 = await Assignments.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Assignment0?.setSchool) {
    await Assignment0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Assignment1 = await Assignments.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Assignment1?.setSchool) {
    await Assignment1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Assignment2 = await Assignments.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Assignment2?.setSchool) {
    await Assignment2.setSchool(relatedSchool2);
  }
}

async function associateBillWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Bill0 = await Bills.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Bill0?.setSchool) {
    await Bill0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Bill1 = await Bills.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Bill1?.setSchool) {
    await Bill1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Bill2 = await Bills.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Bill2?.setSchool) {
    await Bill2.setSchool(relatedSchool2);
  }
}

async function associateBillWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Bill0 = await Bills.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Bill0?.setSchool) {
    await Bill0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Bill1 = await Bills.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Bill1?.setSchool) {
    await Bill1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Bill2 = await Bills.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Bill2?.setSchool) {
    await Bill2.setSchool(relatedSchool2);
  }
}

async function associateClassMessageWithSender() {
  const relatedSender0 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const ClassMessage0 = await ClassMessages.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (ClassMessage0?.setSender) {
    await ClassMessage0.setSender(relatedSender0);
  }

  const relatedSender1 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const ClassMessage1 = await ClassMessages.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (ClassMessage1?.setSender) {
    await ClassMessage1.setSender(relatedSender1);
  }

  const relatedSender2 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const ClassMessage2 = await ClassMessages.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (ClassMessage2?.setSender) {
    await ClassMessage2.setSender(relatedSender2);
  }
}

async function associateClassMessageWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const ClassMessage0 = await ClassMessages.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (ClassMessage0?.setSchool) {
    await ClassMessage0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const ClassMessage1 = await ClassMessages.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (ClassMessage1?.setSchool) {
    await ClassMessage1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const ClassMessage2 = await ClassMessages.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (ClassMessage2?.setSchool) {
    await ClassMessage2.setSchool(relatedSchool2);
  }
}

async function associateClassSubjectWithSubject() {
  const relatedSubject0 = await Subjects.findOne({
    offset: Math.floor(Math.random() * (await Subjects.count())),
  });
  const ClassSubject0 = await ClassSubjects.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (ClassSubject0?.setSubject) {
    await ClassSubject0.setSubject(relatedSubject0);
  }

  const relatedSubject1 = await Subjects.findOne({
    offset: Math.floor(Math.random() * (await Subjects.count())),
  });
  const ClassSubject1 = await ClassSubjects.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (ClassSubject1?.setSubject) {
    await ClassSubject1.setSubject(relatedSubject1);
  }

  const relatedSubject2 = await Subjects.findOne({
    offset: Math.floor(Math.random() * (await Subjects.count())),
  });
  const ClassSubject2 = await ClassSubjects.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (ClassSubject2?.setSubject) {
    await ClassSubject2.setSubject(relatedSubject2);
  }
}

async function associateClassSubjectWithTeacher() {
  const relatedTeacher0 = await Teachers.findOne({
    offset: Math.floor(Math.random() * (await Teachers.count())),
  });
  const ClassSubject0 = await ClassSubjects.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (ClassSubject0?.setTeacher) {
    await ClassSubject0.setTeacher(relatedTeacher0);
  }

  const relatedTeacher1 = await Teachers.findOne({
    offset: Math.floor(Math.random() * (await Teachers.count())),
  });
  const ClassSubject1 = await ClassSubjects.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (ClassSubject1?.setTeacher) {
    await ClassSubject1.setTeacher(relatedTeacher1);
  }

  const relatedTeacher2 = await Teachers.findOne({
    offset: Math.floor(Math.random() * (await Teachers.count())),
  });
  const ClassSubject2 = await ClassSubjects.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (ClassSubject2?.setTeacher) {
    await ClassSubject2.setTeacher(relatedTeacher2);
  }
}

async function associateClassSubjectWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const ClassSubject0 = await ClassSubjects.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (ClassSubject0?.setSchool) {
    await ClassSubject0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const ClassSubject1 = await ClassSubjects.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (ClassSubject1?.setSchool) {
    await ClassSubject1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const ClassSubject2 = await ClassSubjects.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (ClassSubject2?.setSchool) {
    await ClassSubject2.setSchool(relatedSchool2);
  }
}

async function associateClassWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Class0 = await Classes.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Class0?.setSchool) {
    await Class0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Class1 = await Classes.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Class1?.setSchool) {
    await Class1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Class2 = await Classes.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Class2?.setSchool) {
    await Class2.setSchool(relatedSchool2);
  }
}

async function associateClassWithClass_teacher() {
  const relatedClass_teacher0 = await Teachers.findOne({
    offset: Math.floor(Math.random() * (await Teachers.count())),
  });
  const Class0 = await Classes.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Class0?.setClass_teacher) {
    await Class0.setClass_teacher(relatedClass_teacher0);
  }

  const relatedClass_teacher1 = await Teachers.findOne({
    offset: Math.floor(Math.random() * (await Teachers.count())),
  });
  const Class1 = await Classes.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Class1?.setClass_teacher) {
    await Class1.setClass_teacher(relatedClass_teacher1);
  }

  const relatedClass_teacher2 = await Teachers.findOne({
    offset: Math.floor(Math.random() * (await Teachers.count())),
  });
  const Class2 = await Classes.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Class2?.setClass_teacher) {
    await Class2.setClass_teacher(relatedClass_teacher2);
  }
}

async function associateClassWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Class0 = await Classes.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Class0?.setSchool) {
    await Class0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Class1 = await Classes.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Class1?.setSchool) {
    await Class1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Class2 = await Classes.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Class2?.setSchool) {
    await Class2.setSchool(relatedSchool2);
  }
}

async function associateExamSubjectWithExam() {
  const relatedExam0 = await Exams.findOne({
    offset: Math.floor(Math.random() * (await Exams.count())),
  });
  const ExamSubject0 = await ExamSubjects.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (ExamSubject0?.setExam) {
    await ExamSubject0.setExam(relatedExam0);
  }

  const relatedExam1 = await Exams.findOne({
    offset: Math.floor(Math.random() * (await Exams.count())),
  });
  const ExamSubject1 = await ExamSubjects.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (ExamSubject1?.setExam) {
    await ExamSubject1.setExam(relatedExam1);
  }

  const relatedExam2 = await Exams.findOne({
    offset: Math.floor(Math.random() * (await Exams.count())),
  });
  const ExamSubject2 = await ExamSubjects.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (ExamSubject2?.setExam) {
    await ExamSubject2.setExam(relatedExam2);
  }
}

async function associateExamSubjectWithSubject() {
  const relatedSubject0 = await Subjects.findOne({
    offset: Math.floor(Math.random() * (await Subjects.count())),
  });
  const ExamSubject0 = await ExamSubjects.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (ExamSubject0?.setSubject) {
    await ExamSubject0.setSubject(relatedSubject0);
  }

  const relatedSubject1 = await Subjects.findOne({
    offset: Math.floor(Math.random() * (await Subjects.count())),
  });
  const ExamSubject1 = await ExamSubjects.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (ExamSubject1?.setSubject) {
    await ExamSubject1.setSubject(relatedSubject1);
  }

  const relatedSubject2 = await Subjects.findOne({
    offset: Math.floor(Math.random() * (await Subjects.count())),
  });
  const ExamSubject2 = await ExamSubjects.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (ExamSubject2?.setSubject) {
    await ExamSubject2.setSubject(relatedSubject2);
  }
}

async function associateExamSubjectWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const ExamSubject0 = await ExamSubjects.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (ExamSubject0?.setSchool) {
    await ExamSubject0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const ExamSubject1 = await ExamSubjects.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (ExamSubject1?.setSchool) {
    await ExamSubject1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const ExamSubject2 = await ExamSubjects.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (ExamSubject2?.setSchool) {
    await ExamSubject2.setSchool(relatedSchool2);
  }
}

async function associateExamWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Exam0 = await Exams.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Exam0?.setSchool) {
    await Exam0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Exam1 = await Exams.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Exam1?.setSchool) {
    await Exam1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Exam2 = await Exams.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Exam2?.setSchool) {
    await Exam2.setSchool(relatedSchool2);
  }
}

async function associateExamWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Exam0 = await Exams.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Exam0?.setSchool) {
    await Exam0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Exam1 = await Exams.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Exam1?.setSchool) {
    await Exam1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Exam2 = await Exams.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Exam2?.setSchool) {
    await Exam2.setSchool(relatedSchool2);
  }
}

async function associateFeePaymentWithStudent() {
  const relatedStudent0 = await Students.findOne({
    offset: Math.floor(Math.random() * (await Students.count())),
  });
  const FeePayment0 = await FeePayments.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (FeePayment0?.setStudent) {
    await FeePayment0.setStudent(relatedStudent0);
  }

  const relatedStudent1 = await Students.findOne({
    offset: Math.floor(Math.random() * (await Students.count())),
  });
  const FeePayment1 = await FeePayments.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (FeePayment1?.setStudent) {
    await FeePayment1.setStudent(relatedStudent1);
  }

  const relatedStudent2 = await Students.findOne({
    offset: Math.floor(Math.random() * (await Students.count())),
  });
  const FeePayment2 = await FeePayments.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (FeePayment2?.setStudent) {
    await FeePayment2.setStudent(relatedStudent2);
  }
}

async function associateFeePaymentWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const FeePayment0 = await FeePayments.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (FeePayment0?.setSchool) {
    await FeePayment0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const FeePayment1 = await FeePayments.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (FeePayment1?.setSchool) {
    await FeePayment1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const FeePayment2 = await FeePayments.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (FeePayment2?.setSchool) {
    await FeePayment2.setSchool(relatedSchool2);
  }
}

async function associateFeeStructureWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const FeeStructure0 = await FeeStructures.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (FeeStructure0?.setSchool) {
    await FeeStructure0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const FeeStructure1 = await FeeStructures.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (FeeStructure1?.setSchool) {
    await FeeStructure1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const FeeStructure2 = await FeeStructures.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (FeeStructure2?.setSchool) {
    await FeeStructure2.setSchool(relatedSchool2);
  }
}

async function associateFeeStructureWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const FeeStructure0 = await FeeStructures.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (FeeStructure0?.setSchool) {
    await FeeStructure0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const FeeStructure1 = await FeeStructures.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (FeeStructure1?.setSchool) {
    await FeeStructure1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const FeeStructure2 = await FeeStructures.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (FeeStructure2?.setSchool) {
    await FeeStructure2.setSchool(relatedSchool2);
  }
}

async function associateLessonPlanWithTeacher() {
  const relatedTeacher0 = await Teachers.findOne({
    offset: Math.floor(Math.random() * (await Teachers.count())),
  });
  const LessonPlan0 = await LessonPlans.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (LessonPlan0?.setTeacher) {
    await LessonPlan0.setTeacher(relatedTeacher0);
  }

  const relatedTeacher1 = await Teachers.findOne({
    offset: Math.floor(Math.random() * (await Teachers.count())),
  });
  const LessonPlan1 = await LessonPlans.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (LessonPlan1?.setTeacher) {
    await LessonPlan1.setTeacher(relatedTeacher1);
  }

  const relatedTeacher2 = await Teachers.findOne({
    offset: Math.floor(Math.random() * (await Teachers.count())),
  });
  const LessonPlan2 = await LessonPlans.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (LessonPlan2?.setTeacher) {
    await LessonPlan2.setTeacher(relatedTeacher2);
  }
}

async function associateLessonPlanWithSubject() {
  const relatedSubject0 = await Subjects.findOne({
    offset: Math.floor(Math.random() * (await Subjects.count())),
  });
  const LessonPlan0 = await LessonPlans.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (LessonPlan0?.setSubject) {
    await LessonPlan0.setSubject(relatedSubject0);
  }

  const relatedSubject1 = await Subjects.findOne({
    offset: Math.floor(Math.random() * (await Subjects.count())),
  });
  const LessonPlan1 = await LessonPlans.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (LessonPlan1?.setSubject) {
    await LessonPlan1.setSubject(relatedSubject1);
  }

  const relatedSubject2 = await Subjects.findOne({
    offset: Math.floor(Math.random() * (await Subjects.count())),
  });
  const LessonPlan2 = await LessonPlans.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (LessonPlan2?.setSubject) {
    await LessonPlan2.setSubject(relatedSubject2);
  }
}

async function associateLessonPlanWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const LessonPlan0 = await LessonPlans.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (LessonPlan0?.setSchool) {
    await LessonPlan0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const LessonPlan1 = await LessonPlans.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (LessonPlan1?.setSchool) {
    await LessonPlan1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const LessonPlan2 = await LessonPlans.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (LessonPlan2?.setSchool) {
    await LessonPlan2.setSchool(relatedSchool2);
  }
}

async function associateLoginLogWithUser() {
  const relatedUser0 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const LoginLog0 = await LoginLogs.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (LoginLog0?.setUser) {
    await LoginLog0.setUser(relatedUser0);
  }

  const relatedUser1 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const LoginLog1 = await LoginLogs.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (LoginLog1?.setUser) {
    await LoginLog1.setUser(relatedUser1);
  }

  const relatedUser2 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const LoginLog2 = await LoginLogs.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (LoginLog2?.setUser) {
    await LoginLog2.setUser(relatedUser2);
  }
}

async function associateLoginLogWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const LoginLog0 = await LoginLogs.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (LoginLog0?.setSchool) {
    await LoginLog0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const LoginLog1 = await LoginLogs.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (LoginLog1?.setSchool) {
    await LoginLog1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const LoginLog2 = await LoginLogs.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (LoginLog2?.setSchool) {
    await LoginLog2.setSchool(relatedSchool2);
  }
}

async function associateMarkWithStudent() {
  const relatedStudent0 = await Students.findOne({
    offset: Math.floor(Math.random() * (await Students.count())),
  });
  const Mark0 = await Marks.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Mark0?.setStudent) {
    await Mark0.setStudent(relatedStudent0);
  }

  const relatedStudent1 = await Students.findOne({
    offset: Math.floor(Math.random() * (await Students.count())),
  });
  const Mark1 = await Marks.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Mark1?.setStudent) {
    await Mark1.setStudent(relatedStudent1);
  }

  const relatedStudent2 = await Students.findOne({
    offset: Math.floor(Math.random() * (await Students.count())),
  });
  const Mark2 = await Marks.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Mark2?.setStudent) {
    await Mark2.setStudent(relatedStudent2);
  }
}

async function associateMarkWithExam_subject() {
  const relatedExam_subject0 = await ExamSubjects.findOne({
    offset: Math.floor(Math.random() * (await ExamSubjects.count())),
  });
  const Mark0 = await Marks.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Mark0?.setExam_subject) {
    await Mark0.setExam_subject(relatedExam_subject0);
  }

  const relatedExam_subject1 = await ExamSubjects.findOne({
    offset: Math.floor(Math.random() * (await ExamSubjects.count())),
  });
  const Mark1 = await Marks.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Mark1?.setExam_subject) {
    await Mark1.setExam_subject(relatedExam_subject1);
  }

  const relatedExam_subject2 = await ExamSubjects.findOne({
    offset: Math.floor(Math.random() * (await ExamSubjects.count())),
  });
  const Mark2 = await Marks.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Mark2?.setExam_subject) {
    await Mark2.setExam_subject(relatedExam_subject2);
  }
}

async function associateMarkWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Mark0 = await Marks.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Mark0?.setSchool) {
    await Mark0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Mark1 = await Marks.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Mark1?.setSchool) {
    await Mark1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Mark2 = await Marks.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Mark2?.setSchool) {
    await Mark2.setSchool(relatedSchool2);
  }
}

async function associateMessageWithSender() {
  const relatedSender0 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const Message0 = await Messages.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Message0?.setSender) {
    await Message0.setSender(relatedSender0);
  }

  const relatedSender1 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const Message1 = await Messages.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Message1?.setSender) {
    await Message1.setSender(relatedSender1);
  }

  const relatedSender2 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const Message2 = await Messages.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Message2?.setSender) {
    await Message2.setSender(relatedSender2);
  }
}

async function associateMessageWithReceiver() {
  const relatedReceiver0 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const Message0 = await Messages.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Message0?.setReceiver) {
    await Message0.setReceiver(relatedReceiver0);
  }

  const relatedReceiver1 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const Message1 = await Messages.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Message1?.setReceiver) {
    await Message1.setReceiver(relatedReceiver1);
  }

  const relatedReceiver2 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const Message2 = await Messages.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Message2?.setReceiver) {
    await Message2.setReceiver(relatedReceiver2);
  }
}

async function associateMessageWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Message0 = await Messages.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Message0?.setSchool) {
    await Message0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Message1 = await Messages.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Message1?.setSchool) {
    await Message1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Message2 = await Messages.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Message2?.setSchool) {
    await Message2.setSchool(relatedSchool2);
  }
}

async function associateMessageWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Message0 = await Messages.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Message0?.setSchool) {
    await Message0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Message1 = await Messages.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Message1?.setSchool) {
    await Message1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Message2 = await Messages.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Message2?.setSchool) {
    await Message2.setSchool(relatedSchool2);
  }
}

async function associateParentWithUser() {
  const relatedUser0 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const Parent0 = await Parents.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Parent0?.setUser) {
    await Parent0.setUser(relatedUser0);
  }

  const relatedUser1 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const Parent1 = await Parents.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Parent1?.setUser) {
    await Parent1.setUser(relatedUser1);
  }

  const relatedUser2 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const Parent2 = await Parents.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Parent2?.setUser) {
    await Parent2.setUser(relatedUser2);
  }
}

async function associateParentWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Parent0 = await Parents.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Parent0?.setSchool) {
    await Parent0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Parent1 = await Parents.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Parent1?.setSchool) {
    await Parent1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Parent2 = await Parents.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Parent2?.setSchool) {
    await Parent2.setSchool(relatedSchool2);
  }
}

async function associatePeriodSettingWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const PeriodSetting0 = await PeriodSettings.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (PeriodSetting0?.setSchool) {
    await PeriodSetting0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const PeriodSetting1 = await PeriodSettings.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (PeriodSetting1?.setSchool) {
    await PeriodSetting1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const PeriodSetting2 = await PeriodSettings.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (PeriodSetting2?.setSchool) {
    await PeriodSetting2.setSchool(relatedSchool2);
  }
}

async function associatePeriodSettingWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const PeriodSetting0 = await PeriodSettings.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (PeriodSetting0?.setSchool) {
    await PeriodSetting0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const PeriodSetting1 = await PeriodSettings.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (PeriodSetting1?.setSchool) {
    await PeriodSetting1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const PeriodSetting2 = await PeriodSettings.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (PeriodSetting2?.setSchool) {
    await PeriodSetting2.setSchool(relatedSchool2);
  }
}

async function associateSchoolAdminWithUser() {
  const relatedUser0 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const SchoolAdmin0 = await SchoolAdmins.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (SchoolAdmin0?.setUser) {
    await SchoolAdmin0.setUser(relatedUser0);
  }

  const relatedUser1 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const SchoolAdmin1 = await SchoolAdmins.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (SchoolAdmin1?.setUser) {
    await SchoolAdmin1.setUser(relatedUser1);
  }

  const relatedUser2 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const SchoolAdmin2 = await SchoolAdmins.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (SchoolAdmin2?.setUser) {
    await SchoolAdmin2.setUser(relatedUser2);
  }
}

async function associateSchoolAdminWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const SchoolAdmin0 = await SchoolAdmins.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (SchoolAdmin0?.setSchool) {
    await SchoolAdmin0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const SchoolAdmin1 = await SchoolAdmins.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (SchoolAdmin1?.setSchool) {
    await SchoolAdmin1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const SchoolAdmin2 = await SchoolAdmins.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (SchoolAdmin2?.setSchool) {
    await SchoolAdmin2.setSchool(relatedSchool2);
  }
}

async function associateSchoolAdminWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const SchoolAdmin0 = await SchoolAdmins.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (SchoolAdmin0?.setSchool) {
    await SchoolAdmin0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const SchoolAdmin1 = await SchoolAdmins.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (SchoolAdmin1?.setSchool) {
    await SchoolAdmin1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const SchoolAdmin2 = await SchoolAdmins.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (SchoolAdmin2?.setSchool) {
    await SchoolAdmin2.setSchool(relatedSchool2);
  }
}

async function associateStudentAttendanceWithStudent() {
  const relatedStudent0 = await Students.findOne({
    offset: Math.floor(Math.random() * (await Students.count())),
  });
  const StudentAttendance0 = await StudentAttendance.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (StudentAttendance0?.setStudent) {
    await StudentAttendance0.setStudent(relatedStudent0);
  }

  const relatedStudent1 = await Students.findOne({
    offset: Math.floor(Math.random() * (await Students.count())),
  });
  const StudentAttendance1 = await StudentAttendance.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (StudentAttendance1?.setStudent) {
    await StudentAttendance1.setStudent(relatedStudent1);
  }

  const relatedStudent2 = await Students.findOne({
    offset: Math.floor(Math.random() * (await Students.count())),
  });
  const StudentAttendance2 = await StudentAttendance.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (StudentAttendance2?.setStudent) {
    await StudentAttendance2.setStudent(relatedStudent2);
  }
}

async function associateStudentAttendanceWithMarked_by() {
  const relatedMarked_by0 = await Teachers.findOne({
    offset: Math.floor(Math.random() * (await Teachers.count())),
  });
  const StudentAttendance0 = await StudentAttendance.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (StudentAttendance0?.setMarked_by) {
    await StudentAttendance0.setMarked_by(relatedMarked_by0);
  }

  const relatedMarked_by1 = await Teachers.findOne({
    offset: Math.floor(Math.random() * (await Teachers.count())),
  });
  const StudentAttendance1 = await StudentAttendance.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (StudentAttendance1?.setMarked_by) {
    await StudentAttendance1.setMarked_by(relatedMarked_by1);
  }

  const relatedMarked_by2 = await Teachers.findOne({
    offset: Math.floor(Math.random() * (await Teachers.count())),
  });
  const StudentAttendance2 = await StudentAttendance.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (StudentAttendance2?.setMarked_by) {
    await StudentAttendance2.setMarked_by(relatedMarked_by2);
  }
}

async function associateStudentAttendanceWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const StudentAttendance0 = await StudentAttendance.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (StudentAttendance0?.setSchool) {
    await StudentAttendance0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const StudentAttendance1 = await StudentAttendance.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (StudentAttendance1?.setSchool) {
    await StudentAttendance1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const StudentAttendance2 = await StudentAttendance.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (StudentAttendance2?.setSchool) {
    await StudentAttendance2.setSchool(relatedSchool2);
  }
}

async function associateStudentWithUser() {
  const relatedUser0 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const Student0 = await Students.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Student0?.setUser) {
    await Student0.setUser(relatedUser0);
  }

  const relatedUser1 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const Student1 = await Students.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Student1?.setUser) {
    await Student1.setUser(relatedUser1);
  }

  const relatedUser2 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const Student2 = await Students.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Student2?.setUser) {
    await Student2.setUser(relatedUser2);
  }
}

async function associateStudentWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Student0 = await Students.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Student0?.setSchool) {
    await Student0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Student1 = await Students.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Student1?.setSchool) {
    await Student1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Student2 = await Students.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Student2?.setSchool) {
    await Student2.setSchool(relatedSchool2);
  }
}

async function associateStudentWithParent() {
  const relatedParent0 = await Parents.findOne({
    offset: Math.floor(Math.random() * (await Parents.count())),
  });
  const Student0 = await Students.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Student0?.setParent) {
    await Student0.setParent(relatedParent0);
  }

  const relatedParent1 = await Parents.findOne({
    offset: Math.floor(Math.random() * (await Parents.count())),
  });
  const Student1 = await Students.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Student1?.setParent) {
    await Student1.setParent(relatedParent1);
  }

  const relatedParent2 = await Parents.findOne({
    offset: Math.floor(Math.random() * (await Parents.count())),
  });
  const Student2 = await Students.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Student2?.setParent) {
    await Student2.setParent(relatedParent2);
  }
}

async function associateStudentWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Student0 = await Students.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Student0?.setSchool) {
    await Student0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Student1 = await Students.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Student1?.setSchool) {
    await Student1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Student2 = await Students.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Student2?.setSchool) {
    await Student2.setSchool(relatedSchool2);
  }
}

async function associateSubjectWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Subject0 = await Subjects.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Subject0?.setSchool) {
    await Subject0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Subject1 = await Subjects.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Subject1?.setSchool) {
    await Subject1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Subject2 = await Subjects.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Subject2?.setSchool) {
    await Subject2.setSchool(relatedSchool2);
  }
}

async function associateSubjectWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Subject0 = await Subjects.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Subject0?.setSchool) {
    await Subject0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Subject1 = await Subjects.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Subject1?.setSchool) {
    await Subject1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Subject2 = await Subjects.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Subject2?.setSchool) {
    await Subject2.setSchool(relatedSchool2);
  }
}

async function associateTeacherAttendanceWithTeacher() {
  const relatedTeacher0 = await Teachers.findOne({
    offset: Math.floor(Math.random() * (await Teachers.count())),
  });
  const TeacherAttendance0 = await TeacherAttendance.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (TeacherAttendance0?.setTeacher) {
    await TeacherAttendance0.setTeacher(relatedTeacher0);
  }

  const relatedTeacher1 = await Teachers.findOne({
    offset: Math.floor(Math.random() * (await Teachers.count())),
  });
  const TeacherAttendance1 = await TeacherAttendance.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (TeacherAttendance1?.setTeacher) {
    await TeacherAttendance1.setTeacher(relatedTeacher1);
  }

  const relatedTeacher2 = await Teachers.findOne({
    offset: Math.floor(Math.random() * (await Teachers.count())),
  });
  const TeacherAttendance2 = await TeacherAttendance.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (TeacherAttendance2?.setTeacher) {
    await TeacherAttendance2.setTeacher(relatedTeacher2);
  }
}

async function associateTeacherAttendanceWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const TeacherAttendance0 = await TeacherAttendance.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (TeacherAttendance0?.setSchool) {
    await TeacherAttendance0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const TeacherAttendance1 = await TeacherAttendance.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (TeacherAttendance1?.setSchool) {
    await TeacherAttendance1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const TeacherAttendance2 = await TeacherAttendance.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (TeacherAttendance2?.setSchool) {
    await TeacherAttendance2.setSchool(relatedSchool2);
  }
}

async function associateTeacherAttendanceWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const TeacherAttendance0 = await TeacherAttendance.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (TeacherAttendance0?.setSchool) {
    await TeacherAttendance0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const TeacherAttendance1 = await TeacherAttendance.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (TeacherAttendance1?.setSchool) {
    await TeacherAttendance1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const TeacherAttendance2 = await TeacherAttendance.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (TeacherAttendance2?.setSchool) {
    await TeacherAttendance2.setSchool(relatedSchool2);
  }
}

async function associateTeacherWithUser() {
  const relatedUser0 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const Teacher0 = await Teachers.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Teacher0?.setUser) {
    await Teacher0.setUser(relatedUser0);
  }

  const relatedUser1 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const Teacher1 = await Teachers.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Teacher1?.setUser) {
    await Teacher1.setUser(relatedUser1);
  }

  const relatedUser2 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const Teacher2 = await Teachers.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Teacher2?.setUser) {
    await Teacher2.setUser(relatedUser2);
  }
}

async function associateTeacherWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Teacher0 = await Teachers.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Teacher0?.setSchool) {
    await Teacher0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Teacher1 = await Teachers.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Teacher1?.setSchool) {
    await Teacher1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Teacher2 = await Teachers.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Teacher2?.setSchool) {
    await Teacher2.setSchool(relatedSchool2);
  }
}

async function associateTeacherWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Teacher0 = await Teachers.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Teacher0?.setSchool) {
    await Teacher0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Teacher1 = await Teachers.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Teacher1?.setSchool) {
    await Teacher1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Teacher2 = await Teachers.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Teacher2?.setSchool) {
    await Teacher2.setSchool(relatedSchool2);
  }
}

async function associateTimetableWithSubject() {
  const relatedSubject0 = await Subjects.findOne({
    offset: Math.floor(Math.random() * (await Subjects.count())),
  });
  const Timetable0 = await Timetables.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Timetable0?.setSubject) {
    await Timetable0.setSubject(relatedSubject0);
  }

  const relatedSubject1 = await Subjects.findOne({
    offset: Math.floor(Math.random() * (await Subjects.count())),
  });
  const Timetable1 = await Timetables.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Timetable1?.setSubject) {
    await Timetable1.setSubject(relatedSubject1);
  }

  const relatedSubject2 = await Subjects.findOne({
    offset: Math.floor(Math.random() * (await Subjects.count())),
  });
  const Timetable2 = await Timetables.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Timetable2?.setSubject) {
    await Timetable2.setSubject(relatedSubject2);
  }
}

async function associateTimetableWithTeacher() {
  const relatedTeacher0 = await Teachers.findOne({
    offset: Math.floor(Math.random() * (await Teachers.count())),
  });
  const Timetable0 = await Timetables.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Timetable0?.setTeacher) {
    await Timetable0.setTeacher(relatedTeacher0);
  }

  const relatedTeacher1 = await Teachers.findOne({
    offset: Math.floor(Math.random() * (await Teachers.count())),
  });
  const Timetable1 = await Timetables.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Timetable1?.setTeacher) {
    await Timetable1.setTeacher(relatedTeacher1);
  }

  const relatedTeacher2 = await Teachers.findOne({
    offset: Math.floor(Math.random() * (await Teachers.count())),
  });
  const Timetable2 = await Timetables.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Timetable2?.setTeacher) {
    await Timetable2.setTeacher(relatedTeacher2);
  }
}

async function associateTimetableWithSchool() {
  const relatedSchool0 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Timetable0 = await Timetables.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Timetable0?.setSchool) {
    await Timetable0.setSchool(relatedSchool0);
  }

  const relatedSchool1 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Timetable1 = await Timetables.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Timetable1?.setSchool) {
    await Timetable1.setSchool(relatedSchool1);
  }

  const relatedSchool2 = await Schools.findOne({
    offset: Math.floor(Math.random() * (await Schools.count())),
  });
  const Timetable2 = await Timetables.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Timetable2?.setSchool) {
    await Timetable2.setSchool(relatedSchool2);
  }
}

module.exports = {
  up: async (queryInterface, Sequelize) => {
    await ActivityLogs.bulkCreate(ActivityLogsData);

    await AssignmentSubmissions.bulkCreate(AssignmentSubmissionsData);

    await Assignments.bulkCreate(AssignmentsData);

    await Bills.bulkCreate(BillsData);

    await ClassMessages.bulkCreate(ClassMessagesData);

    await ClassSubjects.bulkCreate(ClassSubjectsData);

    await Classes.bulkCreate(ClassesData);

    await ExamSubjects.bulkCreate(ExamSubjectsData);

    await Exams.bulkCreate(ExamsData);

    await FeePayments.bulkCreate(FeePaymentsData);

    await FeeStructures.bulkCreate(FeeStructuresData);

    await LessonPlans.bulkCreate(LessonPlansData);

    await LoginLogs.bulkCreate(LoginLogsData);

    await Marks.bulkCreate(MarksData);

    await Messages.bulkCreate(MessagesData);

    await Parents.bulkCreate(ParentsData);

    await PeriodSettings.bulkCreate(PeriodSettingsData);

    await SchoolAdmins.bulkCreate(SchoolAdminsData);

    await StudentAttendance.bulkCreate(StudentAttendanceData);

    await Students.bulkCreate(StudentsData);

    await Subjects.bulkCreate(SubjectsData);

    await TeacherAttendance.bulkCreate(TeacherAttendanceData);

    await Teachers.bulkCreate(TeachersData);

    await Timetables.bulkCreate(TimetablesData);

    await Schools.bulkCreate(SchoolsData);

    await Promise.all([
      // Similar logic for "relation_many"

      await associateUserWithSchool(),

      await associateActivityLogWithUser(),

      await associateActivityLogWithSchool(),

      await associateAssignmentSubmissionWithAssignment(),

      await associateAssignmentSubmissionWithStudent(),

      await associateAssignmentSubmissionWithSchool(),

      await associateAssignmentWithTeacher(),

      await associateAssignmentWithSubject(),

      await associateAssignmentWithSchool(),

      await associateBillWithSchool(),

      await associateBillWithSchool(),

      await associateClassMessageWithSender(),

      await associateClassMessageWithSchool(),

      await associateClassSubjectWithSubject(),

      await associateClassSubjectWithTeacher(),

      await associateClassSubjectWithSchool(),

      await associateClassWithSchool(),

      await associateClassWithClass_teacher(),

      await associateClassWithSchool(),

      await associateExamSubjectWithExam(),

      await associateExamSubjectWithSubject(),

      await associateExamSubjectWithSchool(),

      await associateExamWithSchool(),

      await associateExamWithSchool(),

      await associateFeePaymentWithStudent(),

      await associateFeePaymentWithSchool(),

      await associateFeeStructureWithSchool(),

      await associateFeeStructureWithSchool(),

      await associateLessonPlanWithTeacher(),

      await associateLessonPlanWithSubject(),

      await associateLessonPlanWithSchool(),

      await associateLoginLogWithUser(),

      await associateLoginLogWithSchool(),

      await associateMarkWithStudent(),

      await associateMarkWithExam_subject(),

      await associateMarkWithSchool(),

      await associateMessageWithSender(),

      await associateMessageWithReceiver(),

      await associateMessageWithSchool(),

      await associateMessageWithSchool(),

      await associateParentWithUser(),

      await associateParentWithSchool(),

      await associatePeriodSettingWithSchool(),

      await associatePeriodSettingWithSchool(),

      await associateSchoolAdminWithUser(),

      await associateSchoolAdminWithSchool(),

      await associateSchoolAdminWithSchool(),

      await associateStudentAttendanceWithStudent(),

      await associateStudentAttendanceWithMarked_by(),

      await associateStudentAttendanceWithSchool(),

      await associateStudentWithUser(),

      await associateStudentWithSchool(),

      await associateStudentWithParent(),

      await associateStudentWithSchool(),

      await associateSubjectWithSchool(),

      await associateSubjectWithSchool(),

      await associateTeacherAttendanceWithTeacher(),

      await associateTeacherAttendanceWithSchool(),

      await associateTeacherAttendanceWithSchool(),

      await associateTeacherWithUser(),

      await associateTeacherWithSchool(),

      await associateTeacherWithSchool(),

      await associateTimetableWithSubject(),

      await associateTimetableWithTeacher(),

      await associateTimetableWithSchool(),
    ]);
  },

  down: async (queryInterface, Sequelize) => {
    await queryInterface.bulkDelete('activity_logs', null, {});

    await queryInterface.bulkDelete('assignment_submissions', null, {});

    await queryInterface.bulkDelete('assignments', null, {});

    await queryInterface.bulkDelete('bills', null, {});

    await queryInterface.bulkDelete('class_messages', null, {});

    await queryInterface.bulkDelete('class_subjects', null, {});

    await queryInterface.bulkDelete('classes', null, {});

    await queryInterface.bulkDelete('exam_subjects', null, {});

    await queryInterface.bulkDelete('exams', null, {});

    await queryInterface.bulkDelete('fee_payments', null, {});

    await queryInterface.bulkDelete('fee_structures', null, {});

    await queryInterface.bulkDelete('lesson_plans', null, {});

    await queryInterface.bulkDelete('login_logs', null, {});

    await queryInterface.bulkDelete('marks', null, {});

    await queryInterface.bulkDelete('messages', null, {});

    await queryInterface.bulkDelete('parents', null, {});

    await queryInterface.bulkDelete('period_settings', null, {});

    await queryInterface.bulkDelete('school_admins', null, {});

    await queryInterface.bulkDelete('student_attendance', null, {});

    await queryInterface.bulkDelete('students', null, {});

    await queryInterface.bulkDelete('subjects', null, {});

    await queryInterface.bulkDelete('teacher_attendance', null, {});

    await queryInterface.bulkDelete('teachers', null, {});

    await queryInterface.bulkDelete('timetables', null, {});

    await queryInterface.bulkDelete('schools', null, {});
  },
};
