<?php

namespace Database\Seeders;

use App\Models\Guru;
use App\Models\GuruMengajar;
use App\Models\Kelas;
use App\Models\MataPelajaran;
use App\Models\TahunAjaran;
use Illuminate\Database\Seeder;

class GuruMengajarSeeder extends Seeder
{
    public function run(): void
    {
        $tahunAjaran = TahunAjaran::where('is_aktif', true)->first();
        $guru        = Guru::first();
        $mapel       = MataPelajaran::where('kode', 'MTK')->first();
        $kelas       = Kelas::where('nama', 'VII-A')->first();

        if (!$tahunAjaran || !$guru || !$mapel || !$kelas) return;

        GuruMengajar::firstOrCreate([
            'guru_id'          => $guru->id,
            'mata_pelajaran_id'=> $mapel->id,
            'kelas_id'         => $kelas->id,
            'tahun_ajaran_id'  => $tahunAjaran->id,
        ]);
    }
}
