<?php

declare(strict_types=1);

namespace apexl\Io\modules\user\hooks;

use apexl\Io\includes\Entity;
use apexl\Io\interfaces\AbstractHook;
use apexl\Io\modules\user\enums\PermissionAction;
use apexl\Io\modules\user\services\EntityPermissionChecker;
use apexl\Io\services\EntityFinderService;
use apexl\Vault\interfaces\driver;

final readonly class ApplyPermissionChecksToEntityFindQuery implements AbstractHook
{
    public function __construct(private EntityPermissionChecker $entityPermissionChecker) {}

    public function hooks(): array
    {
        return [EntityFinderService::HOOK__QUERY];
    }

    public function __invoke(driver $query, Entity $entity): void
    {
        $this->entityPermissionChecker->check($query, $entity, PermissionAction::READ);
    }
}