#!/usr/bin/env bash

set -euo pipefail

BASE_URL="${BASE_URL:-http://localhost:8500}"
ENDPOINT="${BASE_URL%/}/api/exam-sprint/outlook-reports"
RESPONSE_BODY="$(mktemp)"

cleanup() {
  rm -f "$RESPONSE_BODY"
}

trap cleanup EXIT

http_code="$({
  curl -sS \
    -o "$RESPONSE_BODY" \
    -w '%{http_code}' \
    -X POST \
    -H 'Content-Type: application/json' \
    --data-binary @- \
    "$ENDPOINT" <<'JSON'
{
  "StudentName": "20260318测试",
  "StudentStage": 2,
  "StageName": "初中",
  "StageVocabulary": 10,
  "StageExaminName": "中考",
  "StageImportant": 3,
  "StudentWordsLatest": [
    {
      "WordId": 1,
      "MeanId": 101,
      "WordSpell": "ability",
      "WordFrequency": 1,
      "Mastery": 0.9,
      "ReviewTimes": 4,
      "Reliability": 95,
      "CreateTime": "2026-03-18T08:00:00Z"
    },
    {
      "WordId": 2,
      "MeanId": 102,
      "WordSpell": "center",
      "WordFrequency": 3,
      "Mastery": 0.75,
      "ReviewTimes": 3,
      "Reliability": 88,
      "CreateTime": "2026-03-18T08:05:00Z"
    },
    {
      "WordId": 3,
      "MeanId": 103,
      "WordSpell": "father",
      "WordFrequency": 6,
      "Mastery": 0.4,
      "ReviewTimes": 1,
      "Reliability": 70,
      "CreateTime": "2026-03-18T08:10:00Z"
    },
    {
      "WordId": 4,
      "MeanId": 104,
      "WordSpell": "catch",
      "WordFrequency": 9,
      "Mastery": 0.2,
      "ReviewTimes": 0,
      "Reliability": 60,
      "CreateTime": "2026-03-18T08:15:00Z"
    }
  ],
  "MastedWordCount": 4,
  "UnMastedWordCount": 6,
  "ExamineStrangeWordCount": 3,
  "TestPaperWordIdArray": [1, 2, 3, 4, 5],
  "TestPaperTitle": "文章2.jpg",
  "TestPaperUnMasterWords": ["lot", "father", "catch"],
  "TestPaperMastedWords": ["a", "the"],
  "TestPaperMastedWordCount": 2,
  "TestPaperWordCount": 5,
  "Complex": false
}
JSON
})"

printf 'HTTP %s\n' "$http_code"
cat "$RESPONSE_BODY"

if [ "$http_code" != "202" ]; then
  exit 1
fi
