<?php

namespace App\Database\Seeds;

use CodeIgniter\Database\Seeder;
use Faker\Factory;

class UserSeeder extends Seeder
{
    public function run()
    {
        $data = [
            'id'    => 'choi.jh',
            'passwd' => password_hash('1234', PASSWORD_DEFAULT),
            'name'  => '최준흠',
            'email' => 'choi.jh@prime-idc.jp',
            'role'  => 'master',
            'status' => DEFAULT_STATUS,
        ];
        // Using Query Builder
        $this->db->table('user')->insert($data);

        $datas = array();
        for($i=0; $i<50; $i++){
            $datas[] = $this->generate_data();
        }
        // $this->db->table('user')->insertBatch($datas);
    }

    public function generate_data(){
        $faker = Factory::create();
        return [
            "id"        => $faker->userName(),
            "passwd"    => $faker->password(4,10),
            "name"      => $faker->name(),
            "email"     => $faker->email(),
            "role"      => $faker->randomElement(["guest","member","manager","cloudflare","director","master"]),
            "status"    => $faker->randomElement(['use','unuse']),
        ];
    }
}
