<?php

namespace Database\Factories;

use App\Enums\AccountType;
use App\Enums\UserAccountStatus;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;

/**
 * @extends Factory<User>
 */
class UserFactory extends Factory
{
    /**
     * 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 [
            'name' => fake()->name(),
            'email' => fake()->unique()->safeEmail(),
            'role' => 'user',
            'account_type' => AccountType::IndependentAgent,
            'status' => UserAccountStatus::Approved,
            'is_admin' => false,
            'email_verified_at' => now(),
            'password' => static::$password ??= Hash::make('password'),
            'remember_token' => Str::random(10),
        ];
    }

    /**
     * Compte avec droits § 14 (back-office validation).
     */
    public function admin(): static
    {
        return $this->state(fn (): array => [
            'is_admin' => true,
            'status' => UserAccountStatus::Approved,
        ]);
    }

    /** Professionnel en attente pour tests admin. */
    public function pendingProfessional(): static
    {
        return $this->state(fn (): array => [
            'account_type' => AccountType::Agency,
            'status' => UserAccountStatus::Pending,
            'is_admin' => false,
        ]);
    }

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