using System.Diagnostics;
using System.Net.Http;
using System.Text.Json;
using OpenCvSharp;
using SopHelper.Engine.Sop;
/// 显式测试清单指定完成、未开始和接近完成的证据;期望标签绝不发送给视觉服务。
internal static class EvidenceAuditChecks
{
public sealed record Case(int StepId, string Kind, double[] Times, bool ExpectedCompleted);
public static async Task RunAsync(string configPath, string videoPath, string settingsPath, string reportPath, string manifestPath, bool disableThinking)
{
Directory.CreateDirectory(reportPath);
var original = File.ReadAllBytes(configPath);
var config = SopConfigLoader.Load(configPath);
var cases = JsonSerializer.Deserialize(File.ReadAllText(manifestPath), new JsonSerializerOptions { PropertyNameCaseInsensitive = true })!;
if (cases is null || cases.Length == 0) throw new ArgumentException("审计清单不能为空");
using var settings = JsonDocument.Parse(File.ReadAllText(settingsPath));
var root = settings.RootElement;
string Text(string key) => root.TryGetProperty(key, out var value) ? value.GetString() ?? "" : "";
using var http = new HttpClient { Timeout = Timeout.InfiniteTimeSpan };
var client = new ConfiguredVisionDecisionClient(http, new SequenceVisionDecisionClient(http,
new(Text("endpoint"), Text("model"), Text("apiKey"), disableThinking ? false : null)));
using var capture = new VideoCapture(videoPath);
if (!capture.IsOpened() || capture.Fps <= 0) throw new IOException("无法打开审计视频");
var results = new List