<?php

declare(strict_types=1);

namespace Apexl\Tests\Core\Infrastructure;

use apexl\Io\factories\EntityFactory;

/**
 * @method TestEntity create(array $attrs = [], bool $store = true)
 */
final readonly class TestEntityFactory extends EntityFactory
{
    protected function definition(array $attrs): array
    {
        return [
            'name' => $this->nextName(),
        ];
    }

    /**
     * `name` carries a unique index, and the generic varchar filler draws from faker's
     * small word list, so createMany() collided every so often — silently overwriting
     * the earlier row back when inserts were upserts, and now raising instead.
     *
     * 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 nextName(): string
    {
        static $next = 0;

        return sprintf('test-entity-%d', $next++);
    }
}