<?php

declare(strict_types=1);

/*
 * This file is part of the Ferienpass package.
 *
 * (c) Richard Henkenjohann <richard@ferienpass.online>
 *
 * For more information visit the project website <https://ferienpass.online>
 * or the documentation under <https://docs.ferienpass.online>.
 */

namespace Ferienpass\CoreBundle\Fixtures\Factory;

use Doctrine\Common\Collections\ArrayCollection;
use Ferienpass\CoreBundle\Entity\Offer\Base;

use function Zenstruck\Foundry\faker;

use Zenstruck\Foundry\Object\Instantiator;
use Zenstruck\Foundry\ObjectFactory;

class OfferFactory extends ObjectFactory
{
    public function withMaxParticipants(int $max): static
    {
        return $this->with(['maxParticipants' => $max]);
    }

    public function withEdition($edition): static
    {
        return $this->with(['edition' => $edition]);
    }

    public function withAttendances(array $attendances): static
    {
        return $this->with(['attendances' => new ArrayCollection($attendances)]);
    }

    public function withDates(): static
    {
        return $this->with(['dates' => OfferDateFactory::createMany(1, ['offer' => $this])]);
    }

    public static function class(): string
    {
        return Base::class;
    }

    protected function defaults(): array
    {
        return [
            'name' => faker()->realText(40),
            'alias' => 'ferienpass-2021',
        ];
    }

    protected function initialize(): static
    {
        return $this->instantiateWith(Instantiator::withoutConstructor()->alwaysForce('attendances'));
    }
}
