<?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 Ferienpass\CoreBundle\Entity\EditionTask;
use Zenstruck\Foundry\Object\Instantiator;
use Zenstruck\Foundry\ObjectFactory;

class EditionTaskFactory extends ObjectFactory
{
    public function ofTypeHoliday(): static
    {
        return $this->with(['type' => 'holiday']);
    }

    public function ofTypeHostEditingStage(): static
    {
        return $this->with(['type' => 'host_editing_stage']);
    }

    public function ofTypeShowOffers(): static
    {
        return $this->with(['type' => 'show_offers']);
    }

    public function ofTypeFirstComeApplicationSystem(): static
    {
        return $this->with(['type' => 'application_system', 'applicationSystem' => 'firstcome']);
    }

    public function ofTypeLotApplicationSystem(): static
    {
        return $this->with(['type' => 'application_system', 'applicationSystem' => 'lot']);
    }

    public function isInPast(): static
    {
        return $this->with(['periodEnd' => new \DateTimeImmutable('-2 seconds')]);
    }

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

    /** null = unlimited waiting list, 0 = none at all, n = at most n queued. */
    public function withMaxWaitlist(?int $max): static
    {
        return $this->with(['maxWaitlist' => $max]);
    }

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

    protected function defaults(): array
    {
        return [
            'periodBegin' => new \DateTimeImmutable('-1 week'),
            'periodEnd' => new \DateTimeImmutable('+2 months'),
        ];
    }

    protected function initialize(): static
    {
        return $this->instantiateWith(Instantiator::withoutConstructor()->alwaysForce('type', 'applicationSystem', 'periodBegin', 'periodEnd'));
    }
}
