<?php

namespace Database\Factories;

use App\Enums\RolePrincipal;
use App\Enums\StatutCompteUser;
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
{
    protected static ?string $password;

    public function definition(): array
    {
        return [
            'uuid' => Str::uuid(),
            'email' => fake()->unique()->safeEmail(),
            'email_verified_at' => now(),
            'telephone' => fake()->phoneNumber(),
            'password' => static::$password ??= Hash::make('password'),
            'role' => fake()->randomElement(['client', 'candidat', 'admin']),
            'statut' => StatutCompteUser::ACTIF,
            'remember_token' => Str::random(10),
            'derniere_connexion_at' => now(),
        ];
    }

    public function unverified(): static
    {
        return $this->state(fn (array $attributes) => [
            'email_verified_at' => null,
        ]);
    }

    public function client(): static
    {
        return $this->state(fn (array $attributes) => [
            'role' => RolePrincipal::CLIENT,
        ]);
    }

    public function candidat(): static
    {
        return $this->state(fn (array $attributes) => [
            'role' => RolePrincipal::CANDIDAT,
        ]);
    }

    public function admin(): static
    {
        return $this->state(fn (array $attributes) => [
            'role' => RolePrincipal::ADMIN,
        ]);
    }

    public function superAdmin(): static
    {
        return $this->state(fn (array $attributes) => [
            'role' => RolePrincipal::SUPER_ADMIN,
        ]);
    }

    public function suspended(): static
    {
        return $this->state(fn (array $attributes) => [
            'statut' => StatutCompteUser::SUSPENDU,
        ]);
    }
}
