using System;
using System.Linq;
namespace ClassNotify.Shared.Models;
///
/// 设备技术诊断包状态枚举定义 (P2.5 RC1-3 Support Bundle)
/// 严格冻结为 6 个状态,禁止擅自扩充
///
public static class SupportBundleStatuses
{
public const string PendingDispatch = "PendingDispatch";
public const string Collecting = "Collecting";
public const string Available = "Available";
public const string Failed = "Failed";
public const string TimedOut = "TimedOut";
public const string Expired = "Expired";
public static readonly string[] All =
[
PendingDispatch,
Collecting,
Available,
Failed,
TimedOut,
Expired
];
public static bool IsValid(string? status) => !string.IsNullOrEmpty(status) && All.Contains(status);
public static bool IsTerminal(string? status) =>
status == Available || status == Failed || status == TimedOut || status == Expired;
}
///
/// 创建诊断包请求载荷
///
public class CreateSupportBundleRequest
{
public string? ClientRequestId { get; set; }
}
///
/// 诊断包创建响应载荷 (HTTP 202 Accepted)
///
public class SupportBundleCreatedDto
{
public string SupportBundleId { get; set; } = string.Empty;
public string DeviceId { get; set; } = string.Empty;
public string Status { get; set; } = string.Empty;
public DateTimeOffset CreatedAtUtc { get; set; }
public DateTimeOffset DeadlineAtUtc { get; set; }
public string CorrelationId { get; set; } = string.Empty;
}
///
/// SignalR 发送至终端的诊断包生成命令契约 (FormatVersion = 1)
/// 目标通道:t:{tenantId}:d:{deviceId}
///
public sealed class GenerateSupportBundleCommand
{
public int FormatVersion { get; set; } = 1;
public string SupportBundleId { get; set; } = string.Empty;
public string CorrelationId { get; set; } = string.Empty;
public DateTimeOffset RequestedAtUtc { get; set; }
public DateTimeOffset DeadlineAtUtc { get; set; }
public long MaxSizeBytes { get; set; } = 5 * 1024 * 1024;
}
///
/// 诊断包元数据清单 (manifest.json 结构,FormatVersion = 1)
///
public sealed class SupportBundleManifestV1
{
public int FormatVersion { get; set; } = 1;
public string SupportBundleId { get; set; } = string.Empty;
public string DeviceId { get; set; } = string.Empty;
public DateTimeOffset CreatedAtUtc { get; set; }
public string ServiceVersion { get; set; } = string.Empty;
public string? ClientVersion { get; set; }
public string ProtocolVersion { get; set; } = string.Empty;
}
///
/// 诊断包运行期环境快照 (runtime.json 结构)
/// 严格白名单结构化字段,杜绝环境与注册表 Dump
///
public sealed class SupportRuntimeSnapshotV1
{
public string ServiceVersion { get; set; } = string.Empty;
public string? ClientVersion { get; set; }
public string OsVersion { get; set; } = string.Empty;
public string Architecture { get; set; } = string.Empty;
public long ServiceUptimeSeconds { get; set; }
public bool WpfProcessAvailable { get; set; }
public string SignalRState { get; set; } = string.Empty;
public DateTimeOffset? LastSignalRConnectedAtUtc { get; set; }
public DateTimeOffset? LastSignalRDisconnectedAtUtc { get; set; }
public int? HttpsPingLatencyMs { get; set; }
public long? ClockOffsetMs { get; set; }
public string IpcState { get; set; } = string.Empty;
public string TtsState { get; set; } = string.Empty;
}
///
/// 结构化诊断事件记录 (events.ndjson 逐行载荷)
/// 杜绝明文异常堆栈与通知正文,采用白名单 EventCode
///
public sealed record SupportDiagnosticEvent(
DateTimeOffset TimestampUtc,
string Level,
string Component,
string EventCode,
string? CorrelationId,
string? ErrorCode,
long? DurationMs);
///
/// 终端上报诊断采集失败请求
///
public sealed class SupportBundleFailureReportDto
{
public string ErrorCode { get; set; } = SupportBundleErrorCodes.CollectionFailure;
}
///
/// 诊断包标准错误代号字典
///
public static class SupportBundleErrorCodes
{
public const string BundleTooLarge = "BundleTooLarge";
public const string InvalidZip = "InvalidZip";
public const string InvalidManifest = "InvalidManifest";
public const string UnexpectedEntry = "UnexpectedEntry";
public const string ExpandedSizeExceeded = "ExpandedSizeExceeded";
public const string StorageFailure = "StorageFailure";
public const string UploadExpired = "UploadExpired";
public const string CollectionFailure = "CollectionFailure";
public const string BundleAlreadyCompleted = "BundleAlreadyCompleted";
public const string BundleNotAcceptingUpload = "BundleNotAcceptingUpload";
public const string DeviceMismatch = "DeviceMismatch";
public const string SupportBundleAlreadyRunning = "SupportBundleAlreadyRunning";
public const string BundleNotReady = "BundleNotReady";
public const string BundleFailed = "BundleFailed";
public const string BundleExpired = "BundleExpired";
public const string SupportBundleNotFound = "SupportBundleNotFound";
public const string SupportBundleFileMissing = "SupportBundleFileMissing";
public const string InvalidStoragePath = "InvalidStoragePath";
}
///
/// 管理员端诊断包状态查询 DTO (P2.5 RC1-3 Phase 3)
/// 严格白名单结构,杜绝暴露内部物理 StoragePath
///
public sealed class SupportBundleStatusDto
{
public string SupportBundleId { get; set; } = string.Empty;
public string DeviceId { get; set; } = string.Empty;
public string TenantId { get; set; } = string.Empty;
public string Status { get; set; } = string.Empty;
public DateTimeOffset CreatedAtUtc { get; set; }
public DateTimeOffset? CompletedAtUtc { get; set; }
public DateTimeOffset? ExpiresAtUtc { get; set; }
public long? SizeBytes { get; set; }
public string? Sha256 { get; set; }
public bool DownloadAvailable { get; set; }
public string? ErrorCode { get; set; }
}