<?php
/**
 * @copyright (c) Kufer Software GmbH, Oderstraße 7, D-84453 Mühldorf
 */

namespace Kufer\Web\KuferTools\Basis\UseCaseBuilder;

class SpecificToolsAndUserUtils implements ToolsAndUserUtils
{
  
  private $toolSection;

  
  private $user;

  
  public function __construct(ToolSection $toolSection, \Benutzer $user)
  {
    $this->toolSection = $toolSection;
    $this->user = $user;
  }

  public function hasToolAccess(?int $toolSectionId = null): bool
  {
    return \SecurityOperations::checkToolAccess(
      $this->user->getIdentifier(),
      $this->toolSection->getToolId(),
      $toolSectionId ?? $this->toolSection->getToolSectionId()
    );
  }

  public function queryRecht(string $recht, ?int $toolId = null): int
  {
    return \SecurityOperations::privilegAllowed(
      $this->user->getIdentifier(),
      $toolId ?? $this->toolSection->getToolId(),
      $recht
    );
  }

  public function hasRecht(string $recht, ?int $toolId = null): bool
  {
    return $this->queryRecht($recht, $toolId) >= 2;
  }
}