<?php

namespace Database\Seeders;

use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;

class UserSeeder extends Seeder
{
    public function run(): void
    {
        $users = [
            [
                'name'      => 'Super Admin',
                'email'     => 'superadmin@gembira.id',
                'password'  => Hash::make('password123'),
                'is_active' => true,
                'role'      => 'super_admin',
            ],
            [
                'name'      => 'Budi Manager',
                'email'     => 'manager@gembira.id',
                'password'  => Hash::make('password123'),
                'is_active' => true,
                'role'      => 'manager',
            ],
            [
                'name'      => 'Siti Operator',
                'email'     => 'operator@gembira.id',
                'password'  => Hash::make('password123'),
                'is_active' => true,
                'role'      => 'operator',
            ],
        ];

        foreach ($users as $userData) {
            $role = $userData['role'];
            unset($userData['role']);

            $user = User::updateOrCreate(
                ['email' => $userData['email']],
                $userData
            );

            $user->syncRoles([$role]);
        }
    }
}
