<?php

declare(strict_types=1);

namespace apexl\Io\modules\user\EntityFactories;

use apexl\Io\factories\EntityFactory;
use apexl\Io\modules\user\entities\userEntity;

/**
 * @method userEntity create(array $attrs = [], bool $store = true)
 */
final readonly class UserEntityFactory extends EntityFactory
{
    protected function definition(array $attrs): array
    {
        return [
            // email is uniquely indexed and a user is created for nearly every test, so
            // this is the highest-volume unique column in the suite. faker's email()
            // has held up so far, but count instead of trusting the entropy.
            'email' => $this->nextEmail(),
            'first_name' => $this->faker->firstName(),
            'last_name' => $this->faker->lastName(),
            'active' => true,
            'password' => $this->faker->password(32, 32),
            // nfc_key is uniquely indexed, and the generic varchar filler draws from
            // faker's small word list, so two users would eventually claim the same
            // key. Most users have no NFC key at all, so null is also the more
            // representative default.
            'nfc_key' => null,
        ];
    }

    /**
     * A function static rather than a class one: the class is readonly, which makes
     * even a static property readonly and so unable to carry a default.
     */
    private function nextEmail(): string
    {
        static $next = 0;

        return sprintf('user%d@example.org', $next++);
    }
}