<?php

namespace App\Factory;

use App\Entity\User;
use App\Repository\UserRepository;
use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactory;
use Zenstruck\Foundry\ModelFactory;
use Zenstruck\Foundry\Proxy;
use Zenstruck\Foundry\RepositoryProxy;

/**
 * @extends ModelFactory<User>
 */
final class UserFactory extends ModelFactory
{
    CONST string PLAIN_PASSWORD = '12345678';

    public function __construct()
    {
        parent::__construct();
    }

    protected function getDefaults(): array
    {
        $factory = new PasswordHasherFactory([
            'auto' => ['algorithm' => 'auto'],
        ]);
        $hasher = $factory->getPasswordHasher('auto');
        $hash = $hasher->hash(self::PLAIN_PASSWORD);

        return [
            'password' => $hash,
            'roles' => [],
            'groupsView' => 'card',
            'username' => self::faker()->text(180),
        ];
    }

    protected function initialize(): self
    {
        return $this
            // ->afterInstantiate(function(User $user): void {})
        ;
    }

    protected static function getClass(): string
    {
        return User::class;
    }
}
