import type { AuthPermission } from "@/features/auth/auth-data";
import { APP_PERMISSIONS } from "@/features/auth/permissions";

type CanCheck = (permission: AuthPermission) => boolean;

type CdcIssueMatrixAction = "read" | "create" | "update" | "delete";

/**
 * CDC and CEFP share this screen but keep their own backend subjects, so a user
 * may act when they hold the permission on either one. The API works out which
 * matrix they actually get from the role they hold.
 */
export function canUseCdcIssueMatrix(
  can: CanCheck,
  action: CdcIssueMatrixAction,
): boolean {
  return (
    can(APP_PERMISSIONS.cdcIssueMatrix[action]) ||
    can(APP_PERMISSIONS.cefpIssueMatrix[action])
  );
}
