namespace ClassNotify.Shared.Models; /// /// 全局平台统计指标 (超级管理员大盘) /// public class AdminMetricsDto { public int TotalTenants { get; set; } public int TotalClassrooms { get; set; } public int TotalDevices { get; set; } public int OnlineDevices { get; set; } public int OfflineDevices => Math.Max(0, TotalDevices - OnlineDevices); public int TodayNotifications { get; set; } public int AbnormalDevices { get; set; } } /// /// 设备明细与实时状态 DTO /// public class DeviceAdminDto { public string DeviceId { get; set; } = string.Empty; public string TenantId { get; set; } = string.Empty; public string TenantName { get; set; } = string.Empty; public string ClassroomId { get; set; } = string.Empty; public string ClassroomName { get; set; } = string.Empty; public string? Hostname { get; set; } public bool IsOnline { get; set; } public DateTimeOffset? LastHeartbeat { get; set; } public string? ClientVersion { get; set; } public string? ServiceVersion { get; set; } public int? ProtocolVersion { get; set; } public string? OsVersion { get; set; } public string? Architecture { get; set; } public string VersionStatus { get; set; } = "Current"; public string? RemoteIp { get; set; } public string? DisplayLabel { get; set; } public string TenantType { get; set; } = "School"; public bool ServiceRunning { get; set; } = true; public bool ClientRunning { get; set; } = true; // License Management Fields public DateTimeOffset? LicensedUntil { get; set; } public string LicenseTier { get; set; } = "Trial"; public string LicenseStatus { get; set; } = "Valid"; // Valid, ExpiringSoon, Expired, Perpetual public int? RemainingDays { get; set; } public int? RemainingHours { get; set; } } /// /// 学校/租户大盘 DTO /// public class TenantAdminDto { public string Id { get; set; } = string.Empty; public string Name { get; set; } = string.Empty; public string TenantType { get; set; } = "School"; // School, Personal public int ClassroomCount { get; set; } public int DeviceCount { get; set; } public int OnlineCount { get; set; } public bool IsActive { get; set; } = true; public DateTimeOffset CreatedAt { get; set; } } /// /// 激活码详情 DTO /// public class ActivationCodeDto { public string? Id { get; set; } public string Code { get; set; } = string.Empty; public string TenantId { get; set; } = string.Empty; public string TenantName { get; set; } = string.Empty; public string ClassroomId { get; set; } = string.Empty; public string ClassroomName { get; set; } = string.Empty; public DateTimeOffset ExpiresAt { get; set; } public bool IsUsed { get; set; } public DateTimeOffset? UsedAt { get; set; } public string? UsedByDeviceId { get; set; } // License Duration Configuration public int? LicenseDurationDays { get; set; } = 7; public string LicenseTier { get; set; } = "Trial"; public string? Notes { get; set; } // Dual-Distribution & Teacher Direct Assignment (Turn 50) public string? TargetClassName { get; set; } public string? AssignedTeacherId { get; set; } public string? AssignedTeacherName { get; set; } public string DistributionMethod { get; set; } = "External"; // "External" or "TeacherAccount" public DateTimeOffset? AssignedAt { get; set; } public string? AssignedByUserId { get; set; } public string MaskedCode { get; set; } = string.Empty; public DateTimeOffset? SecretExposedAtUtc { get; set; } public string Status { get; set; } = "Issued"; // Draft, Issued, Redeemed, Expired, Revoked public DateTimeOffset? RevokedAtUtc { get; set; } public string? RevokedReason { get; set; } // Live Expiration & License Status Fields (Turn 81) public DateTimeOffset? LicensedUntil { get; set; } public int? RemainingDays { get; set; } public int? RemainingHours { get; set; } public string? LicenseStatus { get; set; } // Valid, ExpiringSoon, Expired public DateTimeOffset? ServerNow { get; set; } public string? TimeZone { get; set; } = "Asia/Shanghai"; } /// /// 设备端/管理端标准设备授权状态 DTO (Server-Authoritative) /// public sealed class DeviceLicenseStatusDto { public string DeviceId { get; set; } = string.Empty; public string Status { get; set; } = "Valid"; // Valid, ExpiringSoon, Expired, Perpetual, OfflineGrace, OfflineRestricted, TimeUntrusted public string Tier { get; set; } = "Trial"; // Trial, AcademicYear, Perpetual, Custom public DateTimeOffset? LicensedUntilUtc { get; set; } public int? RemainingDays { get; set; } public int? RemainingHours { get; set; } public bool IsPerpetual { get; set; } public bool CanReceiveNormalNotifications { get; set; } = true; public bool CanReceiveEmergencyNotifications { get; set; } = true; public string? Message { get; set; } /// /// 服务端权威当前时间 (UTC) /// public DateTimeOffset ServerNowUtc { get; set; } = DateTimeOffset.UtcNow; /// /// 服务端日期键 (yyyy-MM-dd),用于客户端提醒严格每日一次落盘频控 /// public string ReminderDateKey { get; set; } = string.Empty; /// /// 租约颁发时间 (UTC) /// public DateTimeOffset IssuedAtUtc { get; set; } = DateTimeOffset.UtcNow; /// /// 离线容灾宽限截止时间 (UTC)。在此时间前允许继续正常运行,超期后进入 OfflineRestricted /// public DateTimeOffset? OfflineGraceUntilUtc { get; set; } /// /// 服务端签发的防篡改租约签名 (HMAC-SHA256) /// public string? LeaseSignature { get; set; } } /// /// 生成激活码请求 DTO /// public class GenerateActivationCodeRequestDto { public string TenantId { get; set; } = string.Empty; public string ClassId { get; set; } = string.Empty; public int? DurationDays { get; set; } = 7; public string Tier { get; set; } = "Trial"; public string? Notes { get; set; } public int Count { get; set; } = 1; // Dual-Distribution & Teacher Direct Assignment public string DistributionMethod { get; set; } = "External"; // "External" or "TeacherAccount" public string? AssignedTeacherId { get; set; } public string? AssignedTeacherName { get; set; } public string? TargetClassName { get; set; } public string? Purpose { get; set; } = "ProvisionAndLicense"; } /// /// 指派/重新指派激活码给教师或班级请求 DTO /// public class AssignActivationCodeRequestDto { public string Code { get; set; } = string.Empty; public string? TeacherId { get; set; } public string? TeacherName { get; set; } public string? ClassroomId { get; set; } public string? TargetClassName { get; set; } public string? Notes { get; set; } } /// /// 批量标记激活码备注请求 DTO /// public class BatchTagActivationCodesRequestDto { public List Codes { get; set; } = new(); public string? Notes { get; set; } } /// /// 设备续费请求 DTO /// public class RenewDeviceLicenseRequestDto { public string? ActivationCode { get; set; } public int? ExtendDays { get; set; } public DateTimeOffset? ValidThroughDate { get; set; } public string? Tier { get; set; } public string? Reason { get; set; } } /// /// 批量设备续费请求 DTO /// public class BatchRenewDevicesLicenseRequestDto { public string ClientRequestId { get; set; } = string.Empty; public List DeviceIds { get; set; } = new(); public int? ExtendDays { get; set; } public string? ValidThroughLocalDate { get; set; } public DateTimeOffset? ValidThroughDate { get; set; } public string? LicenseKind { get; set; } // "Timed" | "Perpetual" public string? Tier { get; set; } public string? Reason { get; set; } } /// /// 远程指令下发请求 /// public class RemoteCommandRequestDto { public string Command { get; set; } = string.Empty; // "ping", "restart_client", "refresh_config" public string? Parameters { get; set; } } /// /// 创建班级请求 /// public class CreateClassroomDto { public string Id { get; set; } = string.Empty; public string DisplayName { get; set; } = string.Empty; public string? Grade { get; set; } public string? RoomNumber { get; set; } } /// /// 创建教师账号请求 /// public class CreateTeacherDto { public string Username { get; set; } = string.Empty; public string Password { get; set; } = string.Empty; public string FullName { get; set; } = string.Empty; public string Role { get; set; } = "Teacher"; // Teacher, SchoolAdmin } /// /// 消息历史记录与回执 /// public class NotificationRecordDto { public string Id { get; set; } = string.Empty; public string TenantId { get; set; } = string.Empty; public string ClassId { get; set; } = string.Empty; public string ClassName { get; set; } = string.Empty; public string SenderName { get; set; } = string.Empty; public string Message { get; set; } = string.Empty; public string Priority { get; set; } = "Normal"; public DateTimeOffset CreatedAt { get; set; } public string Status { get; set; } = "Sent"; // Sent, Delivered, Acknowledged, Timeout, Failed, Cancelled public bool IsCancelled { get; set; } public DateTimeOffset? CancelledAt { get; set; } public string? CancelledBy { get; set; } public DateTimeOffset? ConfirmedAt { get; set; } public DateTimeOffset? ExpiresAt { get; set; } public List Receipts { get; set; } = new(); } public class UserAdminDto { public string Id { get; set; } = string.Empty; public string TenantId { get; set; } = string.Empty; public string TenantName { get; set; } = string.Empty; public string TenantType { get; set; } = "School"; public string Username { get; set; } = string.Empty; public string FullName { get; set; } = string.Empty; public string Role { get; set; } = string.Empty; public bool IsLocked { get; set; } public DateTimeOffset CreatedAt { get; set; } public DateTimeOffset? LastLoginAt { get; set; } public string? RecoveryEmail { get; set; } } public class UpdateUserAdminRequest { public string? FullName { get; set; } public string? Role { get; set; } public string? TenantId { get; set; } public string? RecoveryEmail { get; set; } } public class CreateUserAdminRequest { public string TenantId { get; set; } = string.Empty; public string Username { get; set; } = string.Empty; public string Password { get; set; } = string.Empty; public string FullName { get; set; } = string.Empty; public string Role { get; set; } = "SchoolAdmin"; // SchoolAdmin, Teacher, TenantOwner } public class ResetPasswordRequest { public string NewPassword { get; set; } = string.Empty; } public class LockUserRequest { public bool IsLocked { get; set; } = true; } public class CreateTenantRequest { public string Id { get; set; } = string.Empty; public string Name { get; set; } = string.Empty; } public class UpdateTenantRequest { public string Name { get; set; } = string.Empty; public bool IsActive { get; set; } = true; } public class UpdateDeviceRequest { public string? Hostname { get; set; } public string? ClassroomId { get; set; } } public class EmergencyBroadcastRequest { public string? TenantId { get; set; } // null or empty = all schools public string Title { get; set; } = "⚠️ 全校紧急通知"; public string Message { get; set; } = string.Empty; public bool Voice { get; set; } = true; public bool Shake { get; set; } = true; public int DurationSeconds { get; set; } = 30; } public class SystemHealthDto { public string Status { get; set; } = "Healthy"; public bool DatabaseConnected { get; set; } = true; public double DatabaseLatencyMs { get; set; } public int ActiveSignalRConnections { get; set; } public int OnlineDevices { get; set; } public string ServerTime { get; set; } = string.Empty; public string Uptime { get; set; } = string.Empty; public long MemoryUsedBytes { get; set; } } public class AdminAuditLogDto { public string Id { get; set; } = string.Empty; public DateTimeOffset OccurredAt { get; set; } public string ActorUsername { get; set; } = string.Empty; public string ActorRole { get; set; } = string.Empty; public string Action { get; set; } = string.Empty; public string TargetType { get; set; } = string.Empty; public string TargetId { get; set; } = string.Empty; public string? Details { get; set; } public string? IpAddress { get; set; } } public sealed class BroadcastReceiptSummaryDto { public string BroadcastId { get; set; } = string.Empty; public int TargetSchools { get; set; } public int TargetClassrooms { get; set; } public int TargetDevices { get; set; } public int Displayed { get; set; } public int Pending { get; set; } public int Cancelled { get; set; } public int Failed { get; set; } public bool Completed => Pending == 0; public DateTimeOffset? CreatedAt { get; set; } } public sealed record CancelNotificationResult( string NotificationId, string TenantId, string ClassroomId, bool AlreadyCancelled, DateTimeOffset? CancelledAt, string? CancelledBy); /// /// 超级管理员专用:设备试用防刷审计与特批台账 DTO /// 绝不暴露完整物理硬件指纹(掩码显示如 8F2A••••91D0),绝不暴露明文券码 /// public sealed class DeviceTrialLedgerAdminDto { public string Id { get; set; } = string.Empty; public string MaskedFingerprint { get; set; } = string.Empty; // e.g. "8F2A••••91D0" public int FingerprintVersion { get; set; } = 1; public string? OriginalDeviceId { get; set; } public string? Hostname { get; set; } public string? OriginalTenantId { get; set; } public string? TenantName { get; set; } public string? TenantType { get; set; } public string? ClassroomId { get; set; } public string? ClassroomName { get; set; } public DateTimeOffset FirstTrialStartedAtUtc { get; set; } public DateTimeOffset TrialEndsAtUtc { get; set; } public string Status { get; set; } = "Active"; // Active, Expired public int BlockedAttemptCount { get; set; } public DateTimeOffset? LastBlockedAtUtc { get; set; } public string OverrideState { get; set; } = "None"; // None, Granted, Consumed, Revoked, Expired public int OverrideRemainingUses { get; set; } public DateTimeOffset? OverrideExpiresAtUtc { get; set; } public string? OverrideReason { get; set; } public string? OverrideGrantedByUserId { get; set; } public DateTimeOffset? OverrideGrantedAtUtc { get; set; } public DateTimeOffset? OverrideConsumedAtUtc { get; set; } public string? SourceActivationCodeId { get; set; } public DateTimeOffset CreatedAtUtc { get; set; } public DateTimeOffset? UpdatedAtUtc { get; set; } } /// /// 超管人工特批一次性试用请求 /// 必须填写经审计的原因,默认 72 小时内单次有效 /// public sealed class GrantTrialOverrideRequestDto { public string Reason { get; set; } = string.Empty; public int ValidHours { get; set; } = 72; // 默认 72 小时 } /// /// 撤销未消费的特批放行请求 /// public sealed class RevokeTrialOverrideRequestDto { public string? Reason { get; set; } } /// /// 服务端全量商业授权审计大盘统计指标(排除测试污染数据) /// public sealed class LicenseRecordsSummaryDto { public int TotalGrantedDays { get; set; } public int ActivationCount { get; set; } public int RenewalCount { get; set; } public int PerpetualCount { get; set; } public int AdjustmentCount { get; set; } public int TotalRecords { get; set; } } public sealed class UpdateDeviceDisplayLabelRequest { public string? DisplayLabel { get; set; } }