<?php

namespace NoahVet\Reef\Test\A_Unit\Application\Security\UseCase;

use NoahVet\Reef\Application\Security\UseCase\RegisterResourceUseCase;
use NoahVet\Reef\Domain\Security\Model\Resource;
use NoahVet\Reef\Domain\Security\Model\ResourceGroupWithMembers;
use NoahVet\Reef\Domain\Security\Model\ResourceType;
use NoahVet\Reef\Domain\Security\Port\ResourceRegistryInterface;
use PHPUnit\Framework\TestCase;

class RegisterResourceUseCaseTest extends TestCase
{
    public function testRegisterDelegatesToRegistry(): void
    {
        $resource = Resource::fromString('reef:phpunit:resource', 'test-id');
        $registry = $this->createMock(ResourceRegistryInterface::class);
        $registry->expects(self::once())->method('register')->with($resource);

        $useCase = new RegisterResourceUseCase($registry);
        $useCase->register($resource);
    }

    public function testRegisterResourceGroupWithMembersDelegatesToRegistry(): void
    {
        $resourceType = ResourceType::fromString('reef:phpunit:resource');
        $group = ResourceGroupWithMembers::fromStringWithMembers($resourceType, 'group-id', ['member-1']);

        $registry = $this->createMock(ResourceRegistryInterface::class);
        $registry->expects(self::once())->method('register')->with($group);

        $useCase = new RegisterResourceUseCase($registry);
        $useCase->register($group);
    }
}
