<?php

namespace App\Secretary\Security;

use App\Secretary\Entity\DoctorSecretary;

class SecretaryPermissionChecker
{
    public function can(DoctorSecretary $secretary, string $resource, string $action): bool
    {
        if (!$secretary->isActive()) {
            return false;
        }

        $permissions = $secretary->getPermissions();

        return (bool) ($permissions['resources'][$resource][$action] ?? false);
    }

    public function canAll(DoctorSecretary $secretary, string $resource, array $actions): bool
    {
        return array_reduce(
            $actions,
            fn(bool $carry, string $action) => $carry && $this->can($secretary, $resource, $action),
            true
        );
    }
}
