<?php

namespace Database\Factories;

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

class UserFactory extends Factory
{
    protected static ?string $password;

    public function definition(): array
    {
        return [
            'name' => fake()->name(),
            'email' => fake()->unique()->safeEmail(),
            'phone' => fake()->phoneNumber(),
            'email_verified_at' => now(),
            'password' => static::$password ??= Hash::make('password'),
            'remember_token' => Str::random(10),
            'role_id' => Role::where('name', 'member')->first()?->id ?? 3,
            'account_status' => 'active',
        ];
    }

    public function admin(): static
    {
        return $this->state(fn (array $attributes) => [
            'role_id' => Role::where('name', 'admin')->first()?->id ?? 1,
        ]);
    }

    public function leasing(): static
    {
        return $this->state(fn (array $attributes) => [
            'role_id' => Role::where('name', 'leasing')->first()?->id ?? 2,
        ]);
    }

    public function member(): static
    {
        return $this->state(fn (array $attributes) => [
            'role_id' => Role::where('name', 'member')->first()?->id ?? 3,
        ]);
    }

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