import { useCommonPermissions } from "./useCommonPermission";

export function useBulletinBoardPermission() {
  const { hasPermission } = usePermission();
  const { bulletinBoardPermissions: permissions } = useCommonPermissions();

  const { userAppRole } = useLocalSetup();

  const canViewBulletinBoard = computed(() => {
    if (!userAppRole.value) return true;
    if (userAppRole.value.permissions.includes("*")) return true;
    return hasPermission(userAppRole.value, permissions, "bulletin-board", "see-all-bulletin-boards");
  });

  const canCreateBulletinBoard = computed(() => {
    if (!userAppRole.value) return true;
    if (userAppRole.value.permissions.includes("*")) return true;
    return hasPermission(userAppRole.value, permissions, "bulletin-board", "add-bulletin-board");
  });

  const canUpdateBulletinBoard = computed(() => {
    if (!userAppRole.value) return true;
    if (userAppRole.value.permissions.includes("*")) return true;
    return hasPermission(userAppRole.value, permissions, "bulletin-board", "update-bulletin-board");
  });

  const canViewBulletinBoardDetails = computed(() => {
    if (!userAppRole.value) return true;
    if (userAppRole.value.permissions.includes("*")) return true;
    return hasPermission(userAppRole.value, permissions, "bulletin-board", "see-bulletin-board-details");
  });



  const canDeleteBulletinBoard = computed(() => {
    if (!userAppRole.value) return true;
    if (userAppRole.value.permissions.includes("*")) return true;
    return hasPermission(userAppRole.value, permissions, "bulletin-board", "delete-bulletin-board");
  });

  return {
    canViewBulletinBoard,
    canCreateBulletinBoard,
    canUpdateBulletinBoard,
    canViewBulletinBoardDetails,
    canDeleteBulletinBoard,
  };
}
