<?php

namespace App\Factory;

use App\Entity\PartnerFollow;
use App\Repository\PartnerFollowRepository;
use Zenstruck\Foundry\ModelFactory;
use Zenstruck\Foundry\Proxy;
use Zenstruck\Foundry\RepositoryProxy;

/**
 * @extends ModelFactory<PartnerFollow>
 *
 * @method        PartnerFollow|Proxy                     create(array|callable $attributes = [])
 * @method static PartnerFollow|Proxy                     createOne(array $attributes = [])
 * @method static PartnerFollow|Proxy                     find(object|array|mixed $criteria)
 * @method static PartnerFollow|Proxy                     findOrCreate(array $attributes)
 * @method static PartnerFollow|Proxy                     first(string $sortedField = 'id')
 * @method static PartnerFollow|Proxy                     last(string $sortedField = 'id')
 * @method static PartnerFollow|Proxy                     random(array $attributes = [])
 * @method static PartnerFollow|Proxy                     randomOrCreate(array $attributes = [])
 * @method static PartnerFollowRepository|RepositoryProxy repository()
 * @method static PartnerFollow[]|Proxy[]                 all()
 * @method static PartnerFollow[]|Proxy[]                 createMany(int $number, array|callable $attributes = [])
 * @method static PartnerFollow[]|Proxy[]                 createSequence(iterable|callable $sequence)
 * @method static PartnerFollow[]|Proxy[]                 findBy(array $attributes)
 * @method static PartnerFollow[]|Proxy[]                 randomRange(int $min, int $max, array $attributes = [])
 * @method static PartnerFollow[]|Proxy[]                 randomSet(int $number, array $attributes = [])
 */
final class PartnerFollowFactory extends ModelFactory
{
    /**
     * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services
     *
     * @todo inject services if required
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories
     *
     * @todo add your default values here
     */
    protected function getDefaults(): array
    {
        $found = true;
        while ($found) {
            $partner = PartnerFactory::random();
            $user = UserFactory::random();
            $follows = PartnerFollowFactory::findBy(['user' => $user, 'partner' => $partner]);
            if (count($follows) === 0) {
                $found = false;
            }
        }
        return [
            'createdAt' => \DateTimeImmutable::createFromMutable(self::faker()->dateTime()),
            'partner' => $partner,
            'user' => $user,
        ];
    }

    /**
     * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#initialization
     */
    protected function initialize(): self
    {
        return $this
            // ->afterInstantiate(function(PartnerFollow $partnerFollow): void {})
        ;
    }

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