<?php

namespace Database\Seeders;

use Faker\Factory as Faker;

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

use App\Models\Payment;
use App\Models\Student;
use App\Models\Subject;

class PaymentSeeder 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);

    Payment::factory()->create([
      'date' => '2023-12-31',

      // NOTE: obsolete field
      'from' => $student_1->email,

      'student_id' => $student_1->id,
      'amount' => '100.00',
      'subject' => $subject_1->subjectTitle,
      'remarks' => '',
    ]);

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

      Payment::factory()->create([
        'date' => '2023-12-' . $index,

        // NOTE: obsolete field
        'from' => 'obsoletestudent@school.com',

        'student_id' => $student->id,
        'amount' => '300.00',
        'subject' => $subject->subjectTitle,
        'remarks' => $subject->subjectTitle . ' tutorial fee',
      ]);
    }
  }
}
