<?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\Tests\ApplicationSystem\Lotting;

use Ferienpass\CoreBundle\ApplicationSystem\Lotting\Seat;
use Ferienpass\CoreBundle\ApplicationSystem\Lotting\Seats;
use Ferienpass\CoreBundle\Entity\Attendance;
use Ferienpass\CoreBundle\Entity\Offer\Base;
use Ferienpass\CoreBundle\Entity\Participant\BaseParticipant;
use PHPUnit\Framework\TestCase;

final class SeatsTest extends TestCase
{
    public function testContainsReturnsTrueWhenParticipantIsInSeat(): void
    {
        $participant = new BaseParticipant();
        $attendance = new Attendance(new Base(), $participant);
        $seat = new Seat([$attendance]);
        $seats = new Seats([$seat]);

        self::assertTrue($seats->contains($participant));
    }

    public function testContainsReturnsFalseWhenParticipantNotPresent(): void
    {
        $participant = new BaseParticipant();
        $otherParticipant = new BaseParticipant();
        $attendance = new Attendance(new Base(), $participant);
        $seat = new Seat([$attendance]);
        $seats = new Seats([$seat]);

        self::assertFalse($seats->contains($otherParticipant));
    }

    public function testContainsReturnsFalseWhenEmpty(): void
    {
        $participant = new BaseParticipant();
        $seats = new Seats([]);

        self::assertFalse($seats->contains($participant));
    }

    public function testContainsSearchesAcrossMultipleSeats(): void
    {
        $participant1 = new BaseParticipant();
        $participant2 = new BaseParticipant();
        $attendance1 = new Attendance(new Base(), $participant1);
        $attendance2 = new Attendance(new Base(), $participant2);

        $seat1 = new Seat([$attendance1]);
        $seat2 = new Seat([$attendance2]);
        $seats = new Seats([$seat1, $seat2]);

        self::assertTrue($seats->contains($participant1));
        self::assertTrue($seats->contains($participant2));
    }
}
