import { NextRequest, NextResponse } from "next/server";
import { queryOne } from "@/lib/db";
import { getSession } from "@/lib/session";

// WBS 템플릿 Task 단건 조회 (project.getWBSTemplateTaskInfo 대응)
export async function POST(request: NextRequest) {
  const user = await getSession();
  if (!user) return NextResponse.json({ success: false }, { status: 401 });

  const { objId } = await request.json();
  if (!objId) return NextResponse.json({ success: true, data: {} });

  const row = await queryOne<Record<string, unknown>>(
    `SELECT T.objid::text AS "OBJID",
       T.parent_objid::text AS "PARENT_OBJID",
       T.task_name AS "TASK_NAME",
       T.task_seq AS "TASK_SEQ",
       T.user_id AS "USER_ID",
       T.unit_no AS "UNIT_NO"
     FROM pms_wbs_task_standard T
     WHERE T.objid = $1`,
    [objId]
  );
  return NextResponse.json({ success: true, data: row ?? {} });
}
