#!/usr/bin/env bash
# 验收家里 NAS + kr HTTPS 生产入口（2026-05-24）
set -euo pipefail

RESOLVE=(--resolve workphone.quwanzhi.com:443:43.139.27.93)
BASE="https://workphone.quwanzhi.com"

check() {
  local path="$1" expect="$2"
  local code body
  code=$(curl -sk -m 15 "${RESOLVE[@]}" -o /tmp/wp_verify_body -w '%{http_code}' "${BASE}${path}")
  body=$(head -c 200 /tmp/wp_verify_body)
  if [[ "$code" == "$expect" ]] || [[ "$body" == *"$expect"* ]]; then
    echo "OK  ${path} → ${code} ${body:0:80}"
  else
    echo "FAIL ${path} → ${code} ${body:0:120}"
    exit 1
  fi
}

echo ">>> 工作手机生产 URL 验收 ${BASE}"
check /health healthy
check /hub 200
check /docs 200
check /api/v3/gateway/info 工作手机SDK
echo ">>> 全部通过"
