<?php

/**
 * Isi ulang tabel data_latih sesuai matriks aturan KelayakanRules.
 * Jalankan: php database/seed_data_latih.php
 */

require_once __DIR__ . '/../config/app.php';
require_once __DIR__ . '/../config/database.php';
require_once __DIR__ . '/../classes/KelayakanRules.php';

$db = getDB();
$pekerjaanList = pekerjaanOrtuList();
$rows = KelayakanRules::generateTrainingRows($pekerjaanList);

$db->exec('DELETE FROM data_latih');
$db->exec('ALTER TABLE data_latih AUTO_INCREMENT = 1');

$stmt = $db->prepare(
    'INSERT INTO data_latih (pekerjaan_ortu, penghasilan_ortu, jumlah_saudara, kepemilikan_kps, kepemilikan_kip, kelas)
     VALUES (?, ?, ?, ?, ?, ?)'
);

foreach ($rows as $row) {
    $stmt->execute([
        $row['pekerjaan_ortu'],
        $row['penghasilan_ortu'],
        $row['jumlah_saudara'],
        $row['kepemilikan_kps'],
        $row['kepemilikan_kip'],
        $row['kelas'],
    ]);
}

echo 'Berhasil mengisi ' . count($rows) . " baris data_latih.\n";
