import { Injectable } from '@angular/core';
import { StorageService } from './storage.service';

@Injectable({
  providedIn: 'root'
})
export class UtilityService {
  constructor(private storage:StorageService) { }

  /***
   * utility classes shared by all the components
   * 
   */

   hasPermission( toCheckPermission:string ): boolean {
    const permissions =  this.storage.getItem('permissions');
    if(permissions?.includes(toCheckPermission))
    {
      // console.log("Is present");
      return true;
      
    }
    else
    {
      // console.log("Not present");
      return false;
    }
  }
hasRole(allowedRoles: string[]): boolean {
  const role = sessionStorage.getItem('role');

  if (!allowedRoles || allowedRoles.length === 0) {
    return true; // no role restriction
  }

  return allowedRoles.includes(role || '');
}

}
