<?php

namespace NoahVet\Reef\Security\IAM;

use NoahVet\Reef\Application\Security\UseCase\RegisterResourceUseCase;
use NoahVet\Reef\Domain\Security\Model\Resource;
use NoahVet\Reef\Domain\Security\Model\ResourceGroupWithMembers;
use NoahVet\Reef\Iam\Client;
use NoahVet\Reef\Infrastructure\Security\Api\JaneResourceRegistry;

/**
 * @deprecated inject RegisterResourceUseCase directly instead
 */
class ResourceManager
{
    private RegisterResourceUseCase $useCase;

    public function __construct(
        Client $iamServiceClient,
    ) {
        $this->useCase = new RegisterResourceUseCase(new JaneResourceRegistry($iamServiceClient));
    }

    /**
     * Create the resource if needed in the IAM.
     */
    public function registerResource(Resource $resource): self
    {
        $this->useCase->register($resource);

        return $this;
    }

    public function register(Resource|ResourceGroupWithMembers $resource): self
    {
        $this->useCase->register($resource);

        return $this;
    }
}
