<?php

namespace Database\Seeders;

use App\Models\User;
use App\Models\Role;
use App\Models\Department;
use Illuminate\Support\Facades\Hash;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    use WithoutModelEvents;

    /**
     * Seed the application's database.
     */
    public function run(): void
    {
        $this->call([RoleDepartmentSeeder::class, RoomSeeder::class]);
        $adminEmail = env('INITIAL_ADMIN_EMAIL');
        $adminPassword = env('INITIAL_ADMIN_PASSWORD');
        if ($adminEmail && $adminPassword) {
            User::updateOrCreate(['email' => $adminEmail], ['name' => env('INITIAL_ADMIN_NAME', 'PhySci Administrator'), 'full_name' => env('INITIAL_ADMIN_NAME', 'PhySci Administrator'), 'role_id' => Role::where('name', 'admin')->value('id'), 'department_id' => Department::where('name', 'Physical Sciences')->value('id'), 'status' => 'active', 'password' => Hash::make($adminPassword)]);
        }
    }
}
