<?php

namespace Database\Seeders;

use App\Models\User;
use App\Models\Department;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class UserSeeder extends Seeder
{
    public function run(): void
    {
        // Get departments
        $hod = Department::where('name', 'HOD')->first();
        $vp = Department::where('name', 'Vice Principal Office')->first();
        $finance = Department::where('name', 'Finance')->first();
        $purchase = Department::where('name', 'Purchase')->first();

        // Admin
        User::create([
            'name' => 'System Admin',
            'email' => 'admin@institution.edu',
            'password' => bcrypt('password'),
            'email_verified_at' => now(),
            'employee_id' => 'ADM001',
            'designation' => 'Administrator',
            'department_id' => $hod->id,
            'role' => 'admin',
        ]);

        // Staff (HOD)
        User::create([
            'name' => 'John Staff',
            'email' => 'staff@institution.edu',
            'password' => bcrypt('password'),
            'email_verified_at' => now(),
            'employee_id' => 'EMP001',
            'designation' => 'Head of Department',
            'department_id' => $hod->id,
            'role' => 'staff',
        ]);

        // VP
        User::create([
            'name' => 'Mary VP',
            'email' => 'vp@institution.edu',
            'password' => bcrypt('password'),
            'email_verified_at' => now(),
            'employee_id' => 'EMP002',
            'designation' => 'Vice Principal',
            'department_id' => $vp->id,
            'role' => 'staff',
        ]);

        // Finance Officer
        User::create([
            'name' => 'Tom Finance',
            'email' => 'finance@institution.edu',
            'password' => bcrypt('password'),
            'email_verified_at' => now(),
            'employee_id' => 'EMP003',
            'designation' => 'Finance Officer',
            'department_id' => $finance->id,
            'role' => 'staff',
        ]);

        // Purchase Officer
        User::create([
            'name' => 'Sara Purchase',
            'email' => 'purchase@institution.edu',
            'password' => bcrypt('password'),
            'email_verified_at' => now(),
            'employee_id' => 'EMP004',
            'designation' => 'Purchase Officer',
            'department_id' => $purchase->id,
            'role' => 'staff',
        ]);
    }
}
