<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

use App\Models\Attendance;
use App\Models\Student;
use App\Models\Subject;

use Faker\Factory as Faker;

class AttendanceSeeder extends Seeder
{
  /**
   * Run the database seeds.
   */
  public function run(): void
  {
    $student_1 = Student::where('email', '=', 'john_ho@school.com')->get()[0];
    $student_2 = Student::where(
      'email',
      '=',
      'sarah_fung@school.com'
    )->get()[0];
    $student_3 = Student::where(
      'email',
      '=',
      'andrew_yip@school.com'
    )->get()[0];

    $subject_1 = Subject::find(1);

    Attendance::factory()->create([
      'check_time' => '2023-04-30 03:17:01',

      // NOTE: obsoleted
      // 'student_email' => 'user@123.com',

      'student_id' => $student_1->id,
      'subject_id' => $subject_1->id,
      'remarks' => '',
    ]);

    $faker = Faker::create();
    foreach (range(2, 30) as $index) {
      $student = Student::find(rand(2, 6));
      $subject = Subject::find(rand(2, 6));

      Attendance::factory()->create([
        'check_time' => '2023-04-30 03:17:' . $index,

        // NOTE: obsoleted
        // 'student_email' => 'user@123.com',

        'student_id' => $student->id,
        'subject_id' => $subject->id,
        'remarks' => 'remarks ' . $index,
      ]);
    }
  }
}
