<?php

namespace Database\Seeders;

// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Database\Seeders\JawabanSeeder;
use Database\Seeders\OrganismSeeder;
use Database\Seeders\SirabSeeder;
use App\User;
 
class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     */
    public function run(): void
    {
        $ceksudah = User::where('username', 'admin')->count();
        if ($ceksudah == 0){
            User::create([
                'nama'      	=>  'Administrator',
                'username' 		=>  'admin',
                'password' 		=>  bcrypt('semangat'),
                'previlage' 	=> 	'developer',
            ]);
        }
        $ceksudah = User::where('username', 'doktestes')->count();
        if ($ceksudah == 0){
            User::create([
                'nama'      	=>  'doktestes',
                'username' 		=>  'doktestes',
                'password' 		=>  bcrypt('doktestes'),
                'previlage' 	=> 	'supervisor',
            ]);
        }
        $ceksudah = User::where('username', 'ppdstes')->count();
        if ($ceksudah == 0){
            User::create([
                'nama'      	=>  'ppdstes',
                'username' 		=>  'ppdstes',
                'password' 		=>  bcrypt('ppdstes'),
                'previlage' 	=> 	'ppds',
            ]);
        }
        $ceksudah = User::where('username', 'analistes')->count();
        if ($ceksudah == 0){
            User::create([
                'nama'      	=>  'analistes',
                'username' 		=>  'analistes',
                'password' 		=>  bcrypt('analistes'),
                'previlage' 	=> 	'analis',
            ]);
        }
        $json1 = file_get_contents(database_path('seeders/data/ruangan.json'));
        $data1 = json_decode($json1, true);
        DB::table('ruangan')->insert($data1);
        $this->call(JawabanSeeder::class);
        $this->call(OrganismSeeder::class);
        $this->call(SirabSeeder::class);
        $this->call(PoliSeeder::class);
    }
}
