export function useCleaningSchedulePermission() {
  const { hasPermission } = usePermission();
  const { permissions } = useCleaningPermission();

  const { userAppRole } = useLocalSetup();

  const canViewSchedules = computed(() => {
    if (!userAppRole.value) return true;
    if (userAppRole.value.permissions.includes("*")) return true;
    return hasPermission(userAppRole.value, permissions, "cleaning-schedule-mgmt", "see-all-schedules");
  });

  const canViewScheduleDetails = computed(() => {
    if (!userAppRole.value) return true;
    if (userAppRole.value.permissions.includes("*")) return true;
    return hasPermission(userAppRole.value, permissions, "cleaning-schedule-mgmt", "see-schedule-details");
  });

  const canDownloadSchedule = computed(() => {
    if (!userAppRole.value) return true;
    if (userAppRole.value.permissions.includes("*")) return true;
    return hasPermission(userAppRole.value, permissions, "cleaning-schedule-mgmt", "download-schedule");
  });

  const canManageScheduleTasks = computed(() => {
    if (!userAppRole.value) return true;
    if (userAppRole.value.permissions.includes("*")) return true;
    return hasPermission(userAppRole.value, permissions, "cleaning-schedule-mgmt", "manage-schedule-tasks");
  });

  const canGenerateChecklist = computed(() => {
    if (!userAppRole.value) return true;
    if (userAppRole.value.permissions.includes("*")) return true;
    return hasPermission(userAppRole.value, permissions, "cleaning-schedule-mgmt", "generate-checklist");
  });

  const canViewHistory = computed(() => {
    if (!userAppRole.value) return true;
    if (userAppRole.value.permissions.includes("*")) return true;
    return hasPermission(userAppRole.value, permissions, "cleaning-schedule-mgmt", "view-history");
  });

  const canAddRemarks = computed(() => {
    if (!userAppRole.value) return true;
    if (userAppRole.value.permissions.includes("*")) return true;
    return hasPermission(userAppRole.value, permissions, "cleaning-schedule-mgmt", "add-remarks");
  });

  return {
    canViewSchedules,
    canViewScheduleDetails,
    canDownloadSchedule,
    canManageScheduleTasks,
    canGenerateChecklist,
    canViewHistory,
    canAddRemarks,
  };
}
