<?php

namespace Database\Seeders;

use App\Models\User;
use Illuminate\Database\Seeder;

class DemoAdminSeeder extends Seeder
{
    private const PASSWORD = 'admin12342026!!';

    private static array $admins = [
        ['name' => 'Emeka Okafor',  'email' => 'josbizhrintranet+admin1@gmail.com', 'role' => 'kyc-manager'],
        ['name' => 'Ngozi Adeyemi', 'email' => 'josbizhrintranet+admin2@gmail.com', 'role' => 'kyc-reviewer'],
        ['name' => 'Tunde Fashola', 'email' => 'josbizhrintranet+admin3@gmail.com', 'role' => 'external'],
    ];

    public function run(): void
    {
        // Update the main admin password to match
        $main = User::where('email', 'admin@josbiz.com')->first();
        if ($main) {
            $main->password = self::PASSWORD;
            $main->save();
        }

        // Create the 3 extra demo admin accounts and assign their demo roles
        foreach (self::$admins as $admin) {
            $user = User::firstOrCreate(
                ['email' => $admin['email']],
                [
                    'name'     => $admin['name'],
                    'password' => self::PASSWORD,
                ]
            );

            if (! $user->hasRole($admin['role'])) {
                $user->assignRole($admin['role']);
            }
        }
    }
}
