#!/bin/bash

# 摄像头厂家初始化脚本
# 使用方法: ./init-camera-vendors.sh <token>
# 示例: ./init-camera-vendors.sh "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

API_BASE="https://tg-live-game.pwtk.cc/api"
TOKEN="$1"

if [ -z "$TOKEN" ]; then
  echo "请提供 token 参数"
  echo "使用方法: ./init-camera-vendors.sh <token>"
  exit 1
fi

echo "开始录入摄像头厂家数据..."

# 1. HIKVISION 海康威视
echo "正在添加: HIKVISION (海康威视)..."
curl -s -X POST "${API_BASE}/admin/camera-vendors/create" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${TOKEN}" \
  -d '{
    "code": "HIKVISION",
    "name": "海康威视",
    "description": "PTZ球机，支持H.264/H.265编码，浏览器可直接播放。型号示例: DS-2DE2A404IW-DE3",
    "supportOnvif": true,
    "supportPtz": true,
    "supportIsapi": true,
    "supportGb28181": true,
    "supportAudio": true,
    "resolution": "1920x1080",
    "defaultPort": 80,
    "defaultRtspPort": 554,
    "rtspUrlTemplate": "rtsp://{username}:{password}@{ip}:{port}/Streaming/Channels/{channel}01",
    "enabled": true,
    "sortOrder": 1
  }'
echo ""

# 2. ANPVIZ
echo "正在添加: ANPVIZ..."
curl -s -X POST "${API_BASE}/admin/camera-vendors/create" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${TOKEN}" \
  -d '{
    "code": "ANPVIZ",
    "name": "ANPVIZ",
    "description": "枪机，H.265编码需FFmpeg转码为H.264。型号示例: L12D2_19_IR_AF。ONVIF专业级支持",
    "supportOnvif": true,
    "supportPtz": false,
    "supportIsapi": false,
    "supportGb28181": false,
    "supportAudio": true,
    "resolution": "1920x1080",
    "defaultPort": 80,
    "defaultRtspPort": 554,
    "rtspUrlTemplate": "rtsp://{username}:{password}@{ip}:{port}/Streaming/Channels/{channel}01",
    "enabled": true,
    "sortOrder": 2
  }'
echo ""

# 3. CT-IP500 (大华风格)
echo "正在添加: CT-IP500..."
curl -s -X POST "${API_BASE}/admin/camera-vendors/create" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${TOKEN}" \
  -d '{
    "code": "CT-IP500",
    "name": "CT-IP500 (杂牌/大华风格)",
    "description": "枪机，H.264编码，浏览器可直接播放。RTSP路径为大华风格。ONVIF端口8999。Web页面无法访问，需用Window查看",
    "supportOnvif": true,
    "supportPtz": false,
    "supportIsapi": false,
    "supportGb28181": false,
    "supportAudio": false,
    "resolution": "1920x1080",
    "defaultPort": 80,
    "defaultRtspPort": 554,
    "rtspUrlTemplate": "rtsp://{username}:{password}@{ip}:{port}/cam/realmonitor?channel={channel}&subtype=0",
    "enabled": true,
    "sortOrder": 3
  }'
echo ""

# 4. SVBC
echo "正在添加: SVBC..."
curl -s -X POST "${API_BASE}/admin/camera-vendors/create" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${TOKEN}" \
  -d '{
    "code": "SVBC",
    "name": "SVBC",
    "description": "枪机，H.265编码(2560x1920)需FFmpeg转码。ONVIF端口8080。RTSP路径简单: /1为主码流, /2为子码流",
    "supportOnvif": true,
    "supportPtz": false,
    "supportIsapi": false,
    "supportGb28181": false,
    "supportAudio": true,
    "resolution": "2560x1920",
    "defaultPort": 80,
    "defaultRtspPort": 554,
    "rtspUrlTemplate": "rtsp://{username}:{password}@{ip}:{port}/{channel}",
    "enabled": true,
    "sortOrder": 4
  }'
echo ""

# 5. Reolink
echo "正在添加: Reolink..."
curl -s -X POST "${API_BASE}/admin/camera-vendors/create" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${TOKEN}" \
  -d '{
    "code": "REOLINK",
    "name": "Reolink",
    "description": "固定摄像头，需要通过Reolink App进行安装配置。需要安装他们的软件，在同一个网络里面扫描二维码进行设备注册",
    "supportOnvif": false,
    "supportPtz": false,
    "supportIsapi": false,
    "supportGb28181": false,
    "supportAudio": true,
    "resolution": "1920x1080",
    "defaultPort": 80,
    "defaultRtspPort": 554,
    "rtspUrlTemplate": "",
    "enabled": true,
    "sortOrder": 5
  }'
echo ""

# 6. DAHUA 大华 (额外添加，因为CT-IP500使用大华风格)
echo "正在添加: DAHUA (大华)..."
curl -s -X POST "${API_BASE}/admin/camera-vendors/create" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${TOKEN}" \
  -d '{
    "code": "DAHUA",
    "name": "大华",
    "description": "大华摄像头，RTSP路径格式: /cam/realmonitor?channel=1&subtype=0 (主码流) 或 subtype=1 (子码流)",
    "supportOnvif": true,
    "supportPtz": true,
    "supportIsapi": false,
    "supportGb28181": true,
    "supportAudio": true,
    "resolution": "1920x1080",
    "defaultPort": 80,
    "defaultRtspPort": 554,
    "rtspUrlTemplate": "rtsp://{username}:{password}@{ip}:{port}/cam/realmonitor?channel={channel}&subtype=0",
    "enabled": true,
    "sortOrder": 6
  }'
echo ""

echo "✅ 摄像头厂家数据录入完成!"
echo ""
echo "录入的厂家列表:"
echo "  1. HIKVISION (海康威视) - PTZ球机"
echo "  2. ANPVIZ - 枪机"
echo "  3. CT-IP500 (杂牌/大华风格) - 枪机"
echo "  4. SVBC - 枪机"
echo "  5. Reolink - 固定摄像头"
echo "  6. DAHUA (大华) - 通用大华风格"
