<?php

namespace Database\Factories;

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

/**
 * @extends Factory<User>
 */
class UserFactory extends Factory
{
    protected $model = User::class;

    /**
     * The current password being used by the factory.
     */
    protected static ?string $password;

    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        return [
            'full_name' => fake()->name(),
            'username' => fake()->unique()->lexify('user_??????'),
            'phone' => null,
            'country_code' => '966',
            'email' => fake()->unique()->safeEmail(),
            'password' => static::$password ??= Hash::make('password'),
            'avatar' => null,
            'wallet_balance' => fake()->randomFloat(2, 0, 5000),
            'reward_points' => fake()->numberBetween(0, 10000),
            'ai_message_count' => 0,
            'level_slug' => 'beginner',
            'login_streak' => 0,
            'longest_login_streak' => 0,
            'last_daily_claim_date' => null,
            'referral_code' => strtoupper(fake()->unique()->bothify('????????')),
            'referred_by_user_id' => null,
            'ai_message_credits' => 0,
            'status' => 'active',
            'is_admin' => false,
            'remember_token' => Str::random(10),
        ];
    }

    /**
     * Indicate that the model's email address should be unverified.
     */
    public function unverified(): static
    {
        return $this->state(fn (array $attributes) => [
            'email' => null,
        ]);
    }

    /** مستخدم بصلاحية دخول لوحة التحكم (للاختبارات). */
    public function admin(): static
    {
        return $this->state(fn (array $attributes) => [
            'is_admin' => true,
        ]);
    }
}
