<?php
namespace Misuzu\Perms;

use stdClass;
use InvalidArgumentException;

trait PermissionResultShared {
    public function checkMany(array $perms): object {
        if(empty($perms))
            throw new InvalidArgumentException('$perms must not be empty.');

        $result = new stdClass;
        $calculated = $this->getCalculated();

        foreach($perms as $name => $perm)
            $result->{$name} = ($calculated & $perm) > 0;

        return $result;
    }

    public function apply(callable $callable): IPermissionResult {
        return new PermissionResult($callable($this->getCalculated()));
    }
}
