<?php

declare(strict_types=1);

/*
 * Chill is a software for social workers
 *
 * For the full copyright and license information, please view
 * the LICENSE file that was distributed with this source code.
 */

namespace Chill\MainBundle\Tests\Services\Regroupement;

use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\Regroupment;
use Chill\MainBundle\Service\Regroupement\CenterRegroupementResolver;
use PHPUnit\Framework\TestCase;

/**
 * @internal
 *
 * @coversNothing
 */
class CenterRegroupementResolverTest extends TestCase
{
    private static CenterRegroupementResolver $resolver;

    public static function setUpBeforeClass(): void
    {
        self::$resolver = new CenterRegroupementResolver();
    }

    /**
     * @dataProvider provideData
     */
    public function testResolveCenter(array $groups, array $centers, array $expected): void
    {
        $actual = self::$resolver->resolveCenters($groups, $centers);

        self::assertEquals(count($expected), count($actual));

        foreach ($expected as $center) {
            self::assertContains($center, $actual);
        }
    }

    public static function provideData(): iterable
    {
        $centerA = new Center();
        $centerB = new Center();
        $centerC = new Center();
        $centerD = new Center();

        $groupA = new Regroupment();
        $groupA->addCenter($centerA)->addCenter($centerB);

        $groupB = new Regroupment();
        $groupB->addCenter($centerA)->addCenter($centerB)->addCenter($centerC);

        yield [
            [$groupA],
            [],
            [$centerA, $centerB],
        ];

        yield [
            [$groupA, $groupB],
            [],
            [$centerA, $centerB, $centerC],
        ];

        yield [
            [$groupA, $groupB],
            [$centerB, $centerD],
            [$centerA, $centerB, $centerC, $centerD],
        ];
    }
}
