<?php
require_once __DIR__ . '/config.php';

echo "=== 测试视频上传 API ===\n\n";

try {
    $stmt = $pdo->query("SELECT COUNT(*) as cnt FROM video_assets");
    $row = $stmt->fetch(PDO::FETCH_ASSOC);
    echo "当前视频记录数: {$row['cnt']}\n\n";
    
    echo "测试创建视频资产...\n";
    $videoId = uniqid('vid_');
    $stmt = $pdo->prepare("INSERT INTO video_assets 
        (video_id, video_name, video_type, storage_path, file_name, file_size, duration, format, is_active, uploaded_by, play_priority, description)
        VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
    
    $stmt->execute([
        $videoId,
        '测试视频',
        'opening',
        'videos/opening/',
        'test_video.mp4',
        1024000,
        120,
        'MP4',
        1,
        'admin',
        1,
        '测试视频描述'
    ]);
    
    echo "✓ 创建成功，video_id: $videoId\n\n";
    
    echo "测试查询视频资产...\n";
    $stmt = $pdo->prepare("SELECT * FROM video_assets WHERE video_id = ?");
    $stmt->execute([$videoId]);
    $asset = $stmt->fetch(PDO::FETCH_ASSOC);
    
    if ($asset) {
        echo "✓ 查询成功:\n";
        echo "  video_id: {$asset['video_id']}\n";
        echo "  video_name: {$asset['video_name']}\n";
        echo "  video_type: {$asset['video_type']}\n";
        echo "  duration: {$asset['duration']}秒\n";
        echo "  format: {$asset['format']}\n";
    } else {
        echo "✗ 查询失败\n";
    }
    
    echo "\n测试删除视频资产...\n";
    $stmt = $pdo->prepare("DELETE FROM video_assets WHERE video_id = ?");
    $stmt->execute([$videoId]);
    echo "✓ 删除成功\n\n";
    
    $stmt = $pdo->query("SELECT COUNT(*) as cnt FROM video_assets");
    $row = $stmt->fetch(PDO::FETCH_ASSOC);
    echo "操作后视频记录数: {$row['cnt']}\n";
    
    echo "\n=== 测试完成 ===\n";
    
} catch (PDOException $e) {
    die("✗ 测试失败: " . $e->getMessage() . "\n");
}
?>