<?php

namespace Database\Factories;

use App\Models\Role;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
 */
class UserFactory extends Factory
{
    protected static ?string $password;

    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        return [
            'role_id' => Role::first()?->id ?? Role::create(['name' => 'admin_tu', 'label' => 'Admin Tata Usaha'])->id,
            'shift_id' => null,
            'name' => fake()->name(),
            'nip_nis' => fake()->numerify('198#####2010011###'),
            'email' => fake()->unique()->safeEmail(),
            'password' => static::$password ??= Hash::make('password123'),
            'force_password_change' => true,
            'is_active' => true,
            'remember_token' => Str::random(10),
        ];
    }
}
