import { jsonFailure, jsonSuccess } from "@/modules/core/server/api";
import { requirePermission } from "@/modules/core/server/auth";
import { listCareExecutionData } from "@/modules/care/server/operations";

export async function GET(): Promise<Response> {
  const auth = await requirePermission("care:read", {
    action: "care.task.list",
    targetType: "care_task",
  });

  if (!auth.success) {
    return auth.response;
  }

  const organizationId = auth.context.organization?.id;
  if (!organizationId) {
    return jsonFailure("请选择机构后查看护理任务", 400);
  }

  const data = await listCareExecutionData(organizationId);
  return jsonSuccess("护理任务已加载", { data });
}
