<?php

namespace App\Database\Seeds;

use CodeIgniter\Database\Seeder;

class DeviceSeeder extends Seeder
{
    public function run()
    {
        $data = [
            [
                'device_code' => 'SMA1-GATE-01',
                'device_name' => 'SMAN1 Gate Device 01',
                'api_key'     => 'devkey123',
                'is_active'   => 1,
                'created_at'  => date('Y-m-d H:i:s'),
                'updated_at'  => date('Y-m-d H:i:s'),
            ],
            [
                'device_code' => 'MOBILE_APP',
                'device_name' => 'Aplikasi Mobile (Presensi Siswa)',
                'api_key'     => 'MOBILE_APP_SECRET',
                'is_active'   => 1,
                'created_at'  => date('Y-m-d H:i:s'),
                'updated_at'  => date('Y-m-d H:i:s'),
            ],
        ];

        $table = $this->db->table('devices');
        foreach ($data as $row) {
            $exists = $table->where('device_code', $row['device_code'])->countAllResults();
            if ($exists === 0) {
                $table->insert($row);
            }
        }
    }
}
