<?php namespace App\Database\Seeds;

use CodeIgniter\Database\Seeder;

class AdminSeeder extends Seeder
{
    public function run()
    {
        $db = \Config\Database::connect();
        $builder = $db->table('users');

        $exists = $builder->where('name','demo.admin')->get()->getRowArray();
        if ($exists) return;

        $passwordHash = password_hash('123123', PASSWORD_DEFAULT);
        $builder->insert([
            'name' => 'demo.admin',
            'email' => 'admin@example.com',
            'phone' => NULL,
            'password' => $passwordHash,
            'role' => 'admin',
            'created_at' => date('Y-m-d H:i:s'),
        ]);
    }
}
