<?php

declare(strict_types=1);

namespace EntitySpecificClassNameServiceTestNamespace {

    use apexl\Io\includes\Entity;

    class Foo
    {

    }

    class BarFoo extends Foo
    {

    }

    class Bar extends Entity
    {

    }

    class Baz extends Entity
    {

    }

    class Fallback
    {

    }
}

namespace Apexl\Tests\Core\UnitTests {

    use apexl\Io\services\EntitySpecificClassNameService;
    use apexl\Io\TestInfrastructure\UnitTest;
    use DI\DependencyException;
    use DI\NotFoundException;
    use EntitySpecificClassNameServiceTestNamespace\Bar;
    use EntitySpecificClassNameServiceTestNamespace\BarFoo;
    use EntitySpecificClassNameServiceTestNamespace\Baz;
    use EntitySpecificClassNameServiceTestNamespace\Fallback;
    use EntitySpecificClassNameServiceTestNamespace\Foo;
    use PHPUnit\Framework\Attributes\Test;
    use function apexl\Io\container;

    class EntitySpecificClassNameServiceTest extends UnitTest
    {
        /**
         * @throws DependencyException
         * @throws NotFoundException
         */
        #[Test]
        public function exists(): void
        {
            $result = container()->get(EntitySpecificClassNameService::class)->class(Foo::class, Bar::class);

            $this->assertSame(BarFoo::class, $result);
        }

        /**
         * @throws DependencyException
         * @throws NotFoundException
         */
        #[Test]
        public function notExists(): void
        {
            $result = container()->get(EntitySpecificClassNameService::class)->class(Foo::class, Baz::class);

            $this->assertSame(Foo::class, $result);
        }

        /**
         * @throws DependencyException
         * @throws NotFoundException
         */
        #[Test]
        public function fallback(): void
        {
            $result = container()->get(EntitySpecificClassNameService::class)->class(
                Foo::class,
                Baz::class,
                Fallback::class
            );

            $this->assertSame(Fallback::class, $result);
        }


    }

}

