<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Models\Kriteria;
use App\Models\SubKriteria;
use App\Models\PengajuanDetail;

class FixPengajuanDetailsSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
    $details = PengajuanDetail::whereNull('kriteria')
                ->orWhereNull('subkriteria_text')
                ->get();

    foreach ($details as $detail) {
        $kriteria = Kriteria::find($detail->kriteria_id);
        $subKriteria = SubKriteria::find($detail->sub_kriteria_id);
        
        if ($kriteria && $subKriteria) {
            $detail->update([
                'kriteria' => $kriteria->nama_kriteria,
                'subkriteria_text' => $subKriteria->nama_subkriteria
            ]);
        }
    }
}
}