<?php

namespace Database\Factories;

use App\Enums\UserStatus;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;

class UserFactory extends Factory
{
    protected $model = User::class;

    public function definition(): array
    {
        return [
            'email' => $this->faker->unique()->safeEmail(),
            'username' => $this->faker->unique()->regexify('[A-Za-z0-9]{8}'),
            'password' => Hash::make(config('myconfig.password_default')),
            'status' => $this->faker->randomElement(UserStatus::cases()),
        ];
    }

    public function active(): Factory
    {
        return $this->state(fn () => ['status' => UserStatus::ACTIVE]);
    }

    public function inactive(): Factory
    {
        return $this->state(fn () => ['status' => UserStatus::INACTIVE]);
    }

    public function verified(): Factory
    {
        return $this->state(fn () => ['email_verified_at' => now()]);
    }
}
