<?php

namespace Database\Seeders;

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

class UserSeeder extends Seeder
{
    public function run(): void
    {
        $roles = Role::query()->pluck('id', 'nama_roles');

        $users = [
            [
                'username' => 'admin',
                'name' => 'Admin',
                'email' => 'admin@example.test',
                'password' => 'admin123',
                'roles_id' => $roles['admin'] ?? null,
            ],
            [
                'username' => 'cashier',
                'name' => 'Cashier',
                'email' => 'cashier@example.test',
                'password' => 'cashier123',
                'roles_id' => $roles['cashier'] ?? null,
            ],
            [
                'username' => 'tablet',
                'name' => 'Tablet',
                'email' => 'tablet@example.test',
                'password' => 'tablet123',
                'roles_id' => $roles['waiter'] ?? null,
            ],
        ];

        foreach ($users as $data) {
            User::firstOrCreate(
                ['username' => $data['username']],
                [
                    'name' => $data['name'],
                    'email' => $data['email'],
                    'password' => Hash::make($data['password']),
                    'roles_id' => $data['roles_id'],
                ]
            );
        }
    }
}
