#!/usr/bin/env node
/**
 * AX 과제 신청 API 테스트 (필수값만)
 * 사용: node scripts/test-ax-apply.js
 * ENABLE_POSTGRES=0: JSON 폴백 사용 (DB 불필요)
 * ENABLE_POSTGRES=1: PostgreSQL 사용 (기본값)
 */
require("dotenv").config({ path: require("path").join(__dirname, "..", ".env") });

const BASE = process.env.TEST_BASE_URL || "http://localhost:8030";

const minimalPayload = {
  department: "테스트부서",
  name: "홍길동",
  workProcessDescription: "테스트",
  painPoint: "테스트",
  currentTimeSpent: "30분",
  errorRateBefore: "5%",
  reasonToSolve: "테스트",
  aiExpectation: "테스트",
  outputType: "테스트",
  participationPledge: true,
};

async function main() {
  console.log("POST", BASE + "/api/ax-apply");
  console.log("Payload (필수값만):", JSON.stringify(minimalPayload, null, 2));
  const res = await fetch(BASE + "/api/ax-apply", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(minimalPayload),
  });
  const body = await res.json().catch(() => ({}));
  console.log("Status:", res.status);
  console.log("Response:", JSON.stringify(body, null, 2));
  process.exit(res.ok && body.ok ? 0 : 1);
}

main().catch((e) => {
  console.error(e);
  process.exit(1);
});
