/*
 * File: D:\shadowed-realms-mobile\ShadowedRealmsMobile\src\server\ShadowedRealms.Admin\Models\AdminViewModels.cs
 * Created: 2025-10-30
 * Last Modified: 2025-11-06
 * Description: Complete view models for admin dashboard including Phase 6 System Health & Monitoring
 * Last Edit Notes: Added Phase 6 System Health & Monitoring ViewModels
 */

using System.ComponentModel.DataAnnotations;

namespace ShadowedRealms.Admin.Models
{
    #region Main Dashboard Models

    /// <summary>
    /// Main admin dashboard view model
    /// </summary>
    public class AdminDashboardViewModel
    {
        public string AdminUser { get; set; } = string.Empty;
        public DateTime AccessTime { get; set; }
        public string AdminRole { get; set; } = string.Empty;
        public DashboardOverviewStatsModel OverviewStats { get; set; } = new();
        public List<AdminActivityModel> RecentActivity { get; set; } = new();
        public SystemHealthModel SystemHealth { get; set; } = new();
        public List<AdminAlertModel> CriticalAlerts { get; set; } = new();
    }

    /// <summary>
    /// Dashboard overview statistics
    /// </summary>
    public class DashboardOverviewStatsModel
    {
        public int TotalPlayers { get; set; }
        public int ActivePlayersToday { get; set; }
        public int TotalAlliances { get; set; }
        public int TotalKingdoms { get; set; }
        public int ActiveKvkEvents { get; set; }
        public decimal TotalRevenue24h { get; set; }
        public decimal TotalRevenue30d { get; set; }
        public int CombatEventsToday { get; set; }
        public int NewRegistrationsToday { get; set; }
        public double AveragePlayerRetentionD7 { get; set; }
        public int CriticalIssueCount { get; set; }
        public DateTime LastUpdated { get; set; }
    }

    /// <summary>
    /// Recent admin activity model
    /// </summary>
    public class AdminActivityModel
    {
        public DateTime Timestamp { get; set; }
        public string ActivityType { get; set; } = string.Empty;
        public string Description { get; set; } = string.Empty;
        public string AdminUser { get; set; } = string.Empty;
        public string Severity { get; set; } = "Info"; // Info, Warning, Critical
        public Dictionary<string, object> Details { get; set; } = new();
    }

    /// <summary>
    /// System health indicators
    /// </summary>
    public class SystemHealthModel
    {
        public string OverallStatus { get; set; } = "Healthy"; // Healthy, Warning, Critical
        public double DatabaseResponseTime { get; set; }
        public double ApiResponseTime { get; set; }
        public int ErrorCount24h { get; set; }
        public double CpuUsage { get; set; }
        public double MemoryUsage { get; set; }
        public double DiskUsage { get; set; }
        public int ActiveConnections { get; set; }
        public DateTime LastHealthCheck { get; set; }
        public List<HealthCheckResult> ComponentHealth { get; set; } = new();
    }

    public class HealthCheckResult
    {
        public string Component { get; set; } = string.Empty;
        public string Status { get; set; } = string.Empty;
        public string Message { get; set; } = string.Empty;
        public DateTime CheckTime { get; set; }
    }

    /// <summary>
    /// Admin alert model
    /// </summary>
    public class AdminAlertModel
    {
        public int AlertId { get; set; }
        public string AlertType { get; set; } = string.Empty;
        public string Title { get; set; } = string.Empty;
        public string Message { get; set; } = string.Empty;
        public string Severity { get; set; } = "Info";
        public DateTime CreatedAt { get; set; }
        public bool IsResolved { get; set; }
        public string? ResolvedBy { get; set; }
        public DateTime? ResolvedAt { get; set; }
        public Dictionary<string, object> AlertData { get; set; } = new();
    }

    #endregion

    #region Player Management Models

    /// <summary>
    /// Player search and management view model
    /// </summary>
    public class PlayerManagementViewModel
    {
        public PlayerSearchModel SearchCriteria { get; set; } = new();
        public List<PlayerSummaryModel> Players { get; set; } = new();
        public int TotalResults { get; set; }
        public int CurrentPage { get; set; }
        public int TotalPages { get; set; }
    }

    public class PlayerSearchModel
    {
        [Display(Name = "Player ID")]
        public int? PlayerId { get; set; }

        [Display(Name = "Player Name")]
        [StringLength(50)]
        public string? PlayerName { get; set; }

        [Display(Name = "Kingdom ID")]
        public int? KingdomId { get; set; }

        [Display(Name = "Alliance ID")]
        public int? AllianceId { get; set; }

        [Display(Name = "VIP Tier")]
        public int? VipTier { get; set; }

        [Display(Name = "Account Status")]
        public string? AccountStatus { get; set; }

        [Display(Name = "Registration Date From")]
        public DateTime? CreatedFrom { get; set; }

        [Display(Name = "Registration Date To")]
        public DateTime? CreatedTo { get; set; }

        [Display(Name = "Last Active From")]
        public DateTime? LastActiveFrom { get; set; }

        [Display(Name = "Last Active To")]
        public DateTime? LastActiveTo { get; set; }
    }

    public class PlayerSummaryModel
    {
        public int PlayerId { get; set; }
        public string PlayerName { get; set; } = string.Empty;
        public int KingdomId { get; set; }
        public int? AllianceId { get; set; }
        public string? AllianceName { get; set; }
        public int CastleLevel { get; set; }
        public decimal Power { get; set; }
        public int VipTier { get; set; }
        public string AccountStatus { get; set; } = string.Empty;
        public DateTime CreatedAt { get; set; }
        public DateTime LastActiveAt { get; set; }
        public decimal TotalSpent { get; set; }
        public bool HasActiveWarnings { get; set; }
    }

    /// <summary>
    /// Enhanced Player Detail Model with Security Monitoring - MOVED FROM CONTROLLER
    /// </summary>
    public class PlayerDetailViewModel
    {
        public int PlayerId { get; set; }
        public string PlayerName { get; set; } = string.Empty;
        public int KingdomId { get; set; }
        public int? AllianceId { get; set; }
        public string? AllianceName { get; set; }
        public int CastleLevel { get; set; }
        public decimal Power { get; set; }
        public int VipTier { get; set; }
        public string AccountStatus { get; set; } = string.Empty;
        public decimal TotalSpent { get; set; }
        public DateTime LastActiveAt { get; set; }
        public DateTime RegistrationDate { get; set; }
        public bool HasActiveWarnings { get; set; }
        public string EmailAddress { get; set; } = string.Empty;

        // Security & IP Monitoring
        public List<IpAddressRecord> IpAddressHistory { get; set; } = new();
        public bool MultipleDevices { get; set; }
        public int DeviceCount { get; set; }
        public List<SecurityAlert> SecurityAlerts { get; set; } = new();

        // Combat Stats
        public int CombatWins { get; set; }
        public int CombatLosses { get; set; }
        public int TroopsLost { get; set; }
        public int TroopsKilled { get; set; }
        public int ResourcesRaided { get; set; }

        // Spending Analysis
        public decimal SpendingLast30Days { get; set; }
        public decimal AverageMonthlySpending { get; set; }
        public bool IsWhale { get; set; }

        // Activity & History
        public List<ActivityRecord> ActivityLog { get; set; } = new();
        public List<PurchaseRecord> PurchaseHistory { get; set; } = new();
        public List<WarningRecord> Warnings { get; set; } = new();
        public string AdminNotes { get; set; } = string.Empty;
    }

    public class PlayerEditViewModel
    {
        public int PlayerId { get; set; }
        public string PlayerName { get; set; } = string.Empty;
        public string EmailAddress { get; set; } = string.Empty;
        public int KingdomId { get; set; }
        public string AccountStatus { get; set; } = string.Empty;
        public int VipTier { get; set; }
        public bool IsEmailConfirmed { get; set; }
        public bool HasActiveWarnings { get; set; }
        public string Notes { get; set; } = string.Empty;
    }

    public class PlayerHistoryViewModel
    {
        public int PlayerId { get; set; }
        public string PlayerName { get; set; } = string.Empty;
        public List<ActivityRecord> ActivityHistory { get; set; } = new();
        public List<LoginRecord> LoginHistory { get; set; } = new();
        public List<PurchaseRecord> PurchaseHistory { get; set; } = new();
    }

    public class PlayerPurchaseHistoryViewModel
    {
        public int PlayerId { get; set; }
        public string PlayerName { get; set; } = string.Empty;
        public decimal TotalSpent { get; set; }
        public List<PurchaseRecord> Purchases { get; set; } = new();
    }

    #endregion

    #region Chat and Kingdom Management Models

    /// <summary>
    /// Chat and Kingdom Management Models - MOVED FROM CONTROLLER
    /// </summary>
    public class ChatLogViewModel
    {
        public int PlayerId { get; set; }
        public string PlayerName { get; set; } = string.Empty;
        public List<ChatMessage> Messages { get; set; } = new();
    }

    public class ChatMessage
    {
        public DateTime Timestamp { get; set; }
        public bool FromAdmin { get; set; }
        public string AdminUser { get; set; } = string.Empty;
        public string Message { get; set; } = string.Empty;
        public string MessageType { get; set; } = string.Empty; // System, Support, Warning
        public Guid MessageId { get; set; }
    }

    public class KingdomDetailViewModel
    {
        public int KingdomId { get; set; }
        public string KingdomName { get; set; } = string.Empty;
        public int PlayerCount { get; set; }
        public int AllianceCount { get; set; }
        public long TotalPower { get; set; }
        public bool KingdomChatEnabled { get; set; }
        public bool HasActiveEvents { get; set; }
        public List<KingdomChatMessage> RecentChatMessages { get; set; } = new();
    }

    public class KingdomChatMessage
    {
        public DateTime Timestamp { get; set; }
        public int PlayerId { get; set; }
        public string PlayerName { get; set; } = string.Empty;
        public string Message { get; set; } = string.Empty;
        public string? AllianceName { get; set; }
        public string MessageType { get; set; } = string.Empty; // General, Alliance, Trade, System
        public bool Flagged { get; set; }
        public string? FlagReason { get; set; }
    }

    #endregion

    #region Security and Activity Models

    /// <summary>
    /// Security and Activity Models - MOVED FROM CONTROLLER
    /// </summary>
    public class IpAddressRecord
    {
        public string IpAddress { get; set; } = string.Empty;
        public string Location { get; set; } = string.Empty;
        public string RiskLevel { get; set; } = string.Empty; // Low, Medium, High
        public DateTime LastSeen { get; set; }
        public DateTime FirstSeen { get; set; }
        public int LoginCount { get; set; }
    }

    public class SecurityAlert
    {
        public string Type { get; set; } = string.Empty;
        public string Message { get; set; } = string.Empty;
        public DateTime Timestamp { get; set; }
        public string Severity { get; set; } = "Medium";
    }

    public class ActivityRecord
    {
        public DateTime Timestamp { get; set; }
        public string Action { get; set; } = string.Empty;
        public string Details { get; set; } = string.Empty;
        public string Severity { get; set; } = "Info"; // Info, Warning, Danger, Success
        public string IpAddress { get; set; } = string.Empty;
        public string UserAgent { get; set; } = string.Empty;
    }

    public class LoginRecord
    {
        public DateTime LoginTime { get; set; }
        public string IpAddress { get; set; } = string.Empty;
        public string Device { get; set; } = string.Empty;
        public bool Successful { get; set; }
        public string Location { get; set; } = string.Empty;
    }

    public class PurchaseRecord
    {
        public DateTime Date { get; set; }
        public decimal Amount { get; set; }
        public string Item { get; set; } = string.Empty;
        public string Status { get; set; } = string.Empty;
        public string TransactionId { get; set; } = string.Empty;
    }

    public class WarningRecord
    {
        public DateTime Date { get; set; }
        public string Reason { get; set; } = string.Empty;
        public string AdminUser { get; set; } = string.Empty;
        public bool IsActive { get; set; }
        public DateTime? ExpiresAt { get; set; }
    }

    #endregion

    #region Analytics Models

    /// <summary>
    /// Player trends analysis
    /// </summary>
    public class PlayerTrendsModel
    {
        public TimeSpan Period { get; set; }
        public List<TrendDataPoint> RegistrationTrend { get; set; } = new();
        public List<TrendDataPoint> ActivityTrend { get; set; } = new();
        public List<TrendDataPoint> RetentionTrend { get; set; } = new();
        public Dictionary<string, int> PlayersByKingdom { get; set; } = new();
        public Dictionary<int, int> PlayersByCastleLevel { get; set; } = new();
    }

    public class TrendDataPoint
    {
        public DateTime Date { get; set; }
        public double Value { get; set; }
        public string Label { get; set; } = string.Empty;
    }

    /// <summary>
    /// VIP analytics model
    /// </summary>
    public class VipAnalyticsModel
    {
        public Dictionary<int, int> VipTierDistribution { get; set; } = new();
        public Dictionary<int, decimal> SpendingByVipTier { get; set; } = new();
        public List<TrendDataPoint> VipConversionTrend { get; set; } = new();
        public decimal AverageSpendPerVipTier { get; set; }
        public int WhaleCount { get; set; }
        public decimal WhaleRevenuePortion { get; set; }
    }

    /// <summary>
    /// Combat analytics model
    /// </summary>
    public class CombatTrendsModel
    {
        public TimeSpan Period { get; set; }
        public int TotalCombatEvents { get; set; }
        public Dictionary<string, int> CombatTypeDistribution { get; set; } = new();
        public Dictionary<string, double> WinRateByPowerRange { get; set; } = new();
        public List<TrendDataPoint> CombatActivityTrend { get; set; } = new();
        public FieldInterceptionAnalyticsModel FieldInterceptionData { get; set; } = new();
        public BalanceAnalyticsModel BalanceData { get; set; } = new();
    }

    /// <summary>
    /// Field Interception Analytics Model - Updated for Phase 4 Combat Analytics
    /// </summary>
    public class FieldInterceptionAnalyticsModel
    {
        // Original properties
        public int TotalInterceptions { get; set; }
        public double InterceptionSuccessRate { get; set; }
        public Dictionary<string, double> InterceptionsByDistance { get; set; } = new();
        public Dictionary<string, double> DefenderAdvantage { get; set; } = new();
        public List<TrendDataPoint> InterceptionUsageTrend { get; set; } = new();

        // Added for Phase 4 Combat Analytics
        public int SuccessfulInterceptions { get; set; }
        public double SuccessRate { get; set; }
        public double AverageInterceptionDistance { get; set; }
        public List<string> PopularInterceptionRoutes { get; set; } = new();
    }

    public class BalanceAnalyticsModel
    {
        public double F2pWinRate { get; set; }
        public double SpenderWinRate { get; set; }
        public double F2pEffectivenessRatio { get; set; }
        public Dictionary<string, double> EffectivenessBySpendingTier { get; set; } = new();
        public List<string> BalanceRecommendations { get; set; } = new();

        // Added for view compatibility
        public string BalanceStatus { get; set; } = "HEALTHY";
        public double SkillBasedVictories { get; set; } = 68.4;
        public double SpendingInfluencedVictories { get; set; } = 23.7;
        public double BalanceScore { get; set; } = 87.3;
    }

    #endregion

    #region Kingdom Management Models

    /// <summary>
    /// Kingdom health overview
    /// </summary>
    public class KingdomHealthModel
    {
        public int KingdomId { get; set; }
        public string KingdomName { get; set; } = string.Empty;
        public int PlayerCount { get; set; }
        public int ActivePlayerCount { get; set; }
        public int AllianceCount { get; set; }
        public double ActivityScore { get; set; }
        public string HealthStatus { get; set; } = string.Empty;
        public DateTime? LastKvkEvent { get; set; }
        public bool IsInKvk { get; set; }
        public Dictionary<string, object> HealthMetrics { get; set; } = new();
        public List<string> HealthIssues { get; set; } = new();
        public List<string> Recommendations { get; set; } = new();
    }

    /// <summary>
    /// KvK analytics model
    /// </summary>
    public class KvkAnalyticsModel
    {
        public int ActiveKvkCount { get; set; }
        public int CompletedKvkCount30d { get; set; }
        public double AverageParticipationRate { get; set; }
        public Dictionary<string, int> VictoryTypeDistribution { get; set; } = new();
        public List<KvkEventSummary> RecentKvkEvents { get; set; } = new();
        public Dictionary<int, double> KingdomPerformanceRatings { get; set; } = new();
    }

    public class KvkEventSummary
    {
        public int KvkId { get; set; }
        public List<int> ParticipatingKingdoms { get; set; } = new();
        public int? WinnerKingdomId { get; set; }
        public DateTime StartTime { get; set; }
        public DateTime? EndTime { get; set; }
        public string EventType { get; set; } = string.Empty;
        public int ParticipantCount { get; set; }
        public Dictionary<string, object> Results { get; set; } = new();
    }

    #endregion

    #region System Performance Models

    /// <summary>
    /// Database performance metrics
    /// </summary>
    public class DatabasePerformanceModel
    {
        public double AverageQueryTime { get; set; }
        public double SlowestQueryTime { get; set; }
        public int QueryCount24h { get; set; }
        public int SlowQueryCount { get; set; }
        public long DatabaseSize { get; set; }
        public int ActiveConnections { get; set; }
        public double CacheHitRatio { get; set; }
        public List<SlowQueryInfo> SlowestQueries { get; set; } = new();
    }

    public class SlowQueryInfo
    {
        public string Query { get; set; } = string.Empty;
        public double ExecutionTime { get; set; }
        public int ExecutionCount { get; set; }
        public DateTime LastExecuted { get; set; }
    }

    /// <summary>
    /// API performance metrics
    /// </summary>
    public class ApiPerformanceModel
    {
        public double AverageResponseTime { get; set; }
        public int RequestCount24h { get; set; }
        public int ErrorCount24h { get; set; }
        public double ErrorRate { get; set; }
        public Dictionary<string, double> EndpointPerformance { get; set; } = new();
        public List<ApiEndpointStats> SlowestEndpoints { get; set; } = new();
    }

    public class ApiEndpointStats
    {
        public string Endpoint { get; set; } = string.Empty;
        public double AverageResponseTime { get; set; }
        public int RequestCount { get; set; }
        public int ErrorCount { get; set; }
        public double ErrorRate { get; set; }
    }

    #endregion

    #region Phase 3: Kingdom Management ViewModels - COMPLETELY FIXED

    /// <summary>
    /// Kingdom management dashboard view model
    /// </summary>
    public class KingdomDashboardViewModel
    {
        public int TotalKingdoms { get; set; }
        public int NewKingdomsToday { get; set; }
        public int TotalPopulation { get; set; }
        public decimal PopulationGrowthRate { get; set; }
        public int ActiveAlliances { get; set; }
        public int ActiveCoalitions { get; set; }
        public int HealthAlerts { get; set; }
        public List<KingdomSummary> Kingdoms { get; set; } = new();
        public List<string> PopulationTrendLabels { get; set; } = new();
        public List<int> PopulationTrendData { get; set; } = new();
        public DateTime LastUpdated { get; set; }
    }

    /// <summary>
    /// Kingdom summary for dashboard display
    /// </summary>
    public class KingdomSummary
    {
        public int Id { get; set; }
        public string Name { get; set; } = string.Empty;
        public int Population { get; set; }
        public int MaxCapacity { get; set; } = 1500;
        public decimal HealthScore { get; set; }
        public int ActiveAlliances { get; set; }
        public int ActiveCoalitions { get; set; }
        public DateTime? LastKvKDate { get; set; }
    }

    /// <summary>
    /// Kingdom health detailed view model
    /// </summary>
    public class KingdomHealthViewModel
    {
        public int KingdomId { get; set; }
        public string KingdomName { get; set; } = string.Empty;
        public decimal OverallHealthScore { get; set; }
        public decimal HealthTrend { get; set; }
        public decimal PopulationScore { get; set; }
        public decimal AllianceActivityScore { get; set; }
        public decimal EconomicScore { get; set; }
        public decimal CombatActivityScore { get; set; }
        public decimal RetentionScore { get; set; }
        public decimal DemocraticScore { get; set; }
        public int TotalPopulation { get; set; }
        public int ActivePlayersToday { get; set; }
        public int ActivePlayersWeek { get; set; }
        public int NewPlayersThisWeek { get; set; }
        public int InactivePlayers { get; set; }
        public int MaxCapacity { get; set; } = 1500;
        public List<AllianceHealthData> AllianceHealthData { get; set; } = new();
        public List<ActivityItem> RecentActivities { get; set; } = new();
        public List<HealthAlert> HealthAlerts { get; set; } = new();
        public DateTime LastUpdated { get; set; }
    }

    public class AllianceHealthData
    {
        public string Name { get; set; } = string.Empty;
        public decimal HealthScore { get; set; }
        public int MemberCount { get; set; }
        public decimal ActivityLevel { get; set; }
        public decimal GrowthRate { get; set; }
    }

    public class ActivityItem
    {
        public string Title { get; set; } = string.Empty;
        public string Description { get; set; } = string.Empty;
        public string Category { get; set; } = string.Empty;
        public string Severity { get; set; } = string.Empty;
        public DateTime Timestamp { get; set; }
    }

    public class HealthAlert
    {
        public string Id { get; set; } = string.Empty;
        public string Title { get; set; } = string.Empty;
        public string Description { get; set; } = string.Empty;
        public string Severity { get; set; } = string.Empty;
        public DateTime Timestamp { get; set; }
    }

    /// <summary>
    /// KvK event management view model
    /// </summary>
    public class KvKManagementViewModel
    {
        public int ActiveEvents { get; set; }
        public int UpcomingEvents { get; set; }
        public int ParticipatingKingdoms { get; set; }
        public int CompletedToday { get; set; }
        public bool AutoMatchmakingEnabled { get; set; }
        public int MatchmakingIntervalHours { get; set; } = 24;
        public decimal PowerBalanceTolerance { get; set; } = 15.0m;
        public List<KvKEventDetails> KvKEvents { get; set; } = new();
        public List<KingdomOption> AvailableKingdoms { get; set; } = new();
        public DateTime LastUpdated { get; set; }
    }

    public class KvKEventDetails
    {
        public string EventId { get; set; } = string.Empty;
        public string EventName { get; set; } = string.Empty;
        public string EventType { get; set; } = string.Empty;
        public string Status { get; set; } = string.Empty;
        public int DurationHours { get; set; }
        public DateTime? StartTime { get; set; }
        public DateTime? CompletionTime { get; set; }
        public int ActualDurationHours { get; set; }
        public List<ParticipatingKingdom> ParticipatingKingdoms { get; set; } = new();
        public ParticipatingKingdom? WinnerKingdom { get; set; }
        public List<EventMilestone> EventMilestones { get; set; } = new();
    }

    public class ParticipatingKingdom
    {
        public string Name { get; set; } = string.Empty;
        public int Population { get; set; }
        public long TotalPower { get; set; }
        public List<string> Coalitions { get; set; } = new();
    }

    public class EventMilestone
    {
        public string Name { get; set; } = string.Empty;
        public string Description { get; set; } = string.Empty;
        public DateTime ScheduledTime { get; set; }
        public bool IsActive { get; set; }
        public bool IsCompleted { get; set; }
    }

    public class KingdomOption
    {
        public int Id { get; set; }
        public string Name { get; set; } = string.Empty;
        public int Population { get; set; }
    }

    /// <summary>
    /// Democratic systems monitoring view model
    /// </summary>
    public class DemocraticSystemsViewModel
    {
        public int KingdomId { get; set; }
        public string KingdomName { get; set; } = string.Empty;
        public decimal VoterTurnoutRate { get; set; }
        public decimal VoterTurnoutTrend { get; set; }
        public int ActiveCandidates { get; set; }
        public int QualifiedCandidates { get; set; }
        public decimal GovernanceScore { get; set; }
        public decimal TaxDistributionTransparency { get; set; }
        public List<CurrentLeader> CurrentLeadership { get; set; } = new();
        public List<ActiveElection> ActiveElections { get; set; } = new();
        public List<ElectionResult> LastElectionResults { get; set; } = new();
        public List<TaxDistribution> TaxDistributions { get; set; } = new();
        public long TotalTaxCollected { get; set; }
        public long TotalTaxDistributed { get; set; }
        public DateTime LastDistributionDate { get; set; }
        public List<GovernanceAlert> GovernanceAlerts { get; set; } = new();
        public DateTime LastUpdated { get; set; }
    }

    public class CurrentLeader
    {
        public string PlayerName { get; set; } = string.Empty;
        public string Position { get; set; } = string.Empty;
        public DateTime ElectedDate { get; set; }
        public DateTime TermEndDate { get; set; }
        public decimal VotePercentage { get; set; }
        public int VoteCount { get; set; }
        public decimal ApprovalRating { get; set; }
    }

    public class ActiveElection
    {
        public string ElectionId { get; set; } = string.Empty;
        public string Position { get; set; } = string.Empty;
        public string Description { get; set; } = string.Empty;
        public string Status { get; set; } = string.Empty;
        public DateTime EndTime { get; set; }
        public int TotalVotes { get; set; }
        public int EligibleVoters { get; set; }
        public decimal TurnoutPercentage { get; set; }
        public List<Candidate> Candidates { get; set; } = new();
    }

    public class Candidate
    {
        public string PlayerName { get; set; } = string.Empty;
        public string Campaign { get; set; } = string.Empty;
        public int VoteCount { get; set; }
        public decimal VotePercentage { get; set; }
    }

    public class ElectionResult
    {
        public string CandidateName { get; set; } = string.Empty;
        public int VoteCount { get; set; }
    }

    public class TaxDistribution
    {
        public string RecipientType { get; set; } = string.Empty;
        public string Description { get; set; } = string.Empty;
        public long Amount { get; set; }
        public decimal Percentage { get; set; }
    }

    public class GovernanceAlert
    {
        public string Id { get; set; } = string.Empty;
        public string Title { get; set; } = string.Empty;
        public string Description { get; set; } = string.Empty;
        public string Severity { get; set; } = string.Empty;
        public DateTime Timestamp { get; set; }
    }

    /// <summary>
    /// Kingdom mergers management view model
    /// </summary>
    public class KingdomMergersViewModel
    {
        public int PendingProposals { get; set; }
        public int ActiveMergers { get; set; }
        public int CompletedMergers { get; set; }
        public int RejectedProposals { get; set; }
        public List<MergerProposalDetails> MergerProposals { get; set; } = new();
        public List<KingdomOption> AvailableKingdoms { get; set; } = new();
        public DateTime LastUpdated { get; set; }
    }

    public class MergerProposalDetails
    {
        public string ProposalId { get; set; } = string.Empty;
        public string Status { get; set; } = string.Empty;
        public DateTime SubmissionDate { get; set; }
        public DateTime? CompletionDate { get; set; }
        public DateTime? EstimatedCompletion { get; set; }
        public string SubmittedBy { get; set; } = string.Empty;
        public string Reason { get; set; } = string.Empty;
        public string? RejectionReason { get; set; }
        public KingdomSummary SourceKingdom { get; set; } = new();
        public KingdomSummary TargetKingdom { get; set; } = new();
        public decimal CompatibilityScore { get; set; }
        public string CompatibilityRating { get; set; } = string.Empty;
        public decimal PowerBalanceRatio { get; set; }
        public decimal CultureCompatibility { get; set; }
        public decimal EconomicSynergy { get; set; }
        public bool VotingRequired { get; set; }
        public List<VotingResult> VotingResults { get; set; } = new();
        public List<MergerStep> MergerSteps { get; set; } = new();
    }

    public class VotingResult
    {
        public string KingdomName { get; set; } = string.Empty;
        public decimal ApprovalPercentage { get; set; }
        public int VotesFor { get; set; }
        public int VotesAgainst { get; set; }
        public decimal TurnoutPercentage { get; set; }
    }

    public class MergerStep
    {
        public string StepName { get; set; } = string.Empty;
        public string Description { get; set; } = string.Empty;
        public bool IsCompleted { get; set; }
        public bool IsActive { get; set; }
        public DateTime? EstimatedCompletion { get; set; }
    }

    /// <summary>
    /// Alliance administration view model
    /// </summary>
    public class AllianceAdministrationViewModel
    {
        public int KingdomId { get; set; }
        public string KingdomName { get; set; } = string.Empty;
        public int TotalAlliances { get; set; }
        public int ActiveCoalitions { get; set; }
        public int TotalMembers { get; set; }
        public int AlliancesNeedingAttention { get; set; }
        public List<AllianceDetails> Alliances { get; set; } = new();
        public List<CoalitionDetails> ActiveCoalitionDetails { get; set; } = new();
        public List<AllianceAlert> AllianceAlerts { get; set; } = new();
        public DateTime LastUpdated { get; set; }
    }

    public class AllianceDetails
    {
        public int AllianceId { get; set; }
        public string Name { get; set; } = string.Empty;
        public string Description { get; set; } = string.Empty;
        public int Level { get; set; }
        public DateTime FoundedDate { get; set; }
        public string Status { get; set; } = string.Empty;
        public int MemberCount { get; set; }
        public long PowerRating { get; set; }
        public decimal ActivityLevel { get; set; }
        public decimal HealthScore { get; set; }
        public DateTime LastActivityDate { get; set; }
        public string? CoalitionName { get; set; }
        public List<LeadershipMember> Leadership { get; set; } = new();
        public PerformanceHistory PerformanceHistory { get; set; } = new();
    }

    public class LeadershipMember
    {
        public string PlayerName { get; set; } = string.Empty;
        public string Position { get; set; } = string.Empty;
        public string Role { get; set; } = string.Empty;
    }

    public class PerformanceHistory
    {
        public List<string> Labels { get; set; } = new();
        public PerformanceData Activity { get; set; } = new();
    }

    public class PerformanceData
    {
        public List<decimal> Data { get; set; } = new();
    }

    public class CoalitionDetails
    {
        public string CoalitionId { get; set; } = string.Empty;
        public string CoalitionName { get; set; } = string.Empty;
        public string Description { get; set; } = string.Empty;
        public DateTime CreatedDate { get; set; }
        public int TotalMembers { get; set; }
        public decimal ActivityScore { get; set; }
        public long CombinedPower { get; set; }
        public decimal KvKParticipation { get; set; }
        public decimal CoordinationScore { get; set; }
        public List<CoalitionMember> MemberAlliances { get; set; } = new();
    }

    public class CoalitionMember
    {
        public string AllianceName { get; set; } = string.Empty;
        public int MemberCount { get; set; }
        public bool IsLeader { get; set; }
    }

    public class AllianceAlert
    {
        public string Id { get; set; } = string.Empty;
        public string AllianceName { get; set; } = string.Empty;
        public string Title { get; set; } = string.Empty;
        public string Description { get; set; } = string.Empty;
        public string Severity { get; set; } = string.Empty;
        public DateTime Timestamp { get; set; }
    }

    /// <summary>
    /// Kingdom health summary for dashboard display
    /// </summary>
    public class KingdomHealthSummary
    {
        public int KingdomId { get; set; }
        public string KingdomName { get; set; } = string.Empty;
        public int Population { get; set; }
        public decimal HealthScore { get; set; }
        public bool IsHealthy { get; set; }
        public DateTime LastActivity { get; set; }
        public int ActiveAlliances { get; set; }
        public decimal KvKParticipation { get; set; }
    }

    /// <summary>
    /// Merger proposal summary
    /// </summary>
    public class MergerProposal
    {
        public int ProposalId { get; set; }
        public List<int> SourceKingdoms { get; set; } = new();
        public int TargetKingdom { get; set; }
        public string Status { get; set; } = string.Empty;
        public DateTime ProposalDate { get; set; }
        public Dictionary<string, object> VotingResults { get; set; } = new();
    }

    #endregion

    #region Phase 4: Combat Analytics ViewModels - ADDED

    /// <summary>
    /// Main Combat Analytics Dashboard ViewModel - COMPLETE
    /// </summary>
    public class CombatAnalyticsViewModel
    {
        public TimeSpan Period { get; set; } = TimeSpan.FromDays(30);
        public DateTime LastUpdated { get; set; } = DateTime.UtcNow;
        public CombatOverviewModel CombatOverview { get; set; } = new();
        public BalanceAnalyticsModel BalanceMetrics { get; set; } = new();
        public DragonAnalyticsModel DragonAnalytics { get; set; } = new();
        public FieldInterceptionAnalyticsModel InterceptionAnalytics { get; set; } = new();
    }

    /// <summary>
    /// Combat Effectiveness Analysis ViewModel - COMPLETE
    /// </summary>
    public class CombatEffectivenessViewModel
    {
        public int KingdomId { get; set; }
        public TimeSpan Period { get; set; } = TimeSpan.FromDays(30);
        public DateTime LastUpdated { get; set; } = DateTime.UtcNow;
        public AntiPayToWinMetricsModel AntiPayToWinMetrics { get; set; } = new();
        public Dictionary<string, object> SpendingInfluenceAnalysis { get; set; } = new();
        public List<PlayerEffectivenessData> PlayerEffectivenessData { get; set; } = new();
    }

    /// <summary>
    /// Battle Analytics Dashboard ViewModel - COMPLETE
    /// </summary>
    public class BattleAnalyticsViewModel
    {
        public int CurrentPage { get; set; } = 1;
        public int TotalPages { get; set; }
        public string SortBy { get; set; } = "Date";
        public string Filter { get; set; } = "All";
        public DateTime LastUpdated { get; set; } = DateTime.UtcNow;
        public Dictionary<string, object> BattleTrends { get; set; } = new();
        public List<BattleSummary> RecentBattles { get; set; } = new();
    }

    /// <summary>
    /// Dragon Analytics Dashboard ViewModel - COMPLETE
    /// </summary>
    public class DragonAnalyticsViewModel
    {
        public DateTime LastUpdated { get; set; } = DateTime.UtcNow;
        public DragonAnalyticsModel OverallMetrics { get; set; } = new();
        public Dictionary<string, object> SkillVsPremiumAnalysis { get; set; } = new();
        public List<DragonUsageData> DragonUsageByType { get; set; } = new();
    }

    /// <summary>
    /// Field Interception Analytics ViewModel - COMPLETE
    /// </summary>
    public class FieldInterceptionViewModel
    {
        public DateTime LastUpdated { get; set; } = DateTime.UtcNow;
        public FieldInterceptionAnalyticsModel InterceptionMetrics { get; set; } = new();
        public Dictionary<string, object> StrategicImpact { get; set; } = new();
        public List<TerrainInterceptionData> InterceptionsByTerrain { get; set; } = new();
    }

    /// <summary>
    /// Combat Overview Model - NEW
    /// </summary>
    public class CombatOverviewModel
    {
        public int TotalBattles { get; set; }
        public int TotalCasualties { get; set; }
        public double FieldInterceptionRate { get; set; }
        public double DragonUsageRate { get; set; }
        public double AverageBalanceScore { get; set; }
        public double F2pEffectivenessRatio { get; set; }
    }

    /// <summary>
    /// Dragon Analytics Model - NEW
    /// </summary>
    public class DragonAnalyticsModel
    {
        public int TotalDragonDeployments { get; set; }
        public double SkillBasedUsage { get; set; }
        public double PremiumFeatureUsage { get; set; }
        public double EffectivenessRatio { get; set; }
        public List<string> TopSkillCategories { get; set; } = new();
    }

    /// <summary>
    /// Anti-Pay-to-Win Metrics Model - NEW
    /// </summary>
    public class AntiPayToWinMetricsModel
    {
        public double F2pEffectivenessRatio { get; set; }
        public double BalanceScore { get; set; }
        public List<string> BalanceIssues { get; set; } = new();
        public List<string> Recommendations { get; set; } = new();
        public DateTime? LastBalanceCheck { get; set; } = DateTime.UtcNow;
    }

    /// <summary>
    /// Player Effectiveness Data - NEW
    /// </summary>
    public class PlayerEffectivenessData
    {
        public string SpendingTier { get; set; } = string.Empty;
        public double WinRate { get; set; }
        public double EffectivenessScore { get; set; }
        public int PlayerCount { get; set; }
    }

    /// <summary>
    /// Battle Summary Data - NEW
    /// </summary>
    public class BattleSummary
    {
        public int BattleId { get; set; }
        public string AttackerName { get; set; } = string.Empty;
        public string DefenderName { get; set; } = string.Empty;
        public string BattleType { get; set; } = string.Empty;
        public string Outcome { get; set; } = string.Empty;
        public double PowerDifference { get; set; }
        public double SpendingInfluence { get; set; }
        public double SkillFactor { get; set; }
        public DateTime Timestamp { get; set; } = DateTime.UtcNow;
    }

    /// <summary>
    /// Dragon Usage Data by Type - NEW
    /// </summary>
    public class DragonUsageData
    {
        public string DragonType { get; set; } = string.Empty;
        public double SkillUsage { get; set; }
        public double PremiumUsage { get; set; }
        public int TotalDeployments { get; set; }
    }

    /// <summary>
    /// Terrain Interception Data - NEW
    /// </summary>
    public class TerrainInterceptionData
    {
        public string TerrainType { get; set; } = string.Empty;
        public int InterceptionCount { get; set; }
        public double SuccessRate { get; set; }
        public double DefenderAdvantage { get; set; }
    }

    #endregion

    #region Phase 5: Revenue Analytics & Monetization Health ViewModels - ADDED

    /// <summary>
    /// Main Revenue Analytics Dashboard ViewModel
    /// </summary>
    public class RevenueAnalyticsViewModel
    {
        public TimeSpan Period { get; set; } = TimeSpan.FromDays(30);
        public DateTime LastUpdated { get; set; } = DateTime.UtcNow;

        // Core Revenue Metrics
        public decimal TotalRevenue { get; set; }
        public decimal Revenue24h { get; set; }
        public decimal Revenue7d { get; set; }
        public decimal Revenue30d { get; set; }
        public decimal MRR { get; set; } // Monthly Recurring Revenue
        public decimal ARPPU { get; set; } // Average Revenue Per Paying User
        public decimal ARPU { get; set; } // Average Revenue Per User
        public double ConversionRate { get; set; } // F2P to Paying conversion %
        public decimal LTV { get; set; } // Customer Lifetime Value
        public double ChurnRate { get; set; }

        // Spending Distribution
        public Dictionary<string, decimal> RevenueBySpendingTier { get; set; } = new();

        // Anti-Pay-to-Win Validation
        public double F2PEffectivenessRatio { get; set; }
        public double SpendingInfluenceOnVictories { get; set; }
        public double BalanceScore { get; set; }

        // Monetization Health
        public double MonetizationHealthScore { get; set; }
    }

    /// <summary>
    /// VIP Progression Analytics ViewModel
    /// </summary>
    public class VipProgressionViewModel
    {
        public DateTime LastUpdated { get; set; } = DateTime.UtcNow;

        // VIP Tier Distribution
        public Dictionary<int, int> VipTierDistribution { get; set; } = new();

        // Secret Tier Tracking (KoA-inspired)
        public List<SecretTierProgressionData> SecretTierProgressionData { get; set; } = new();

        // VIP Progression Rates
        public List<VipProgressionRate> VipProgressionRates { get; set; } = new();

        // Monthly/Yearly Reward Eligibility
        public int MonthlyRewardEligibleCount { get; set; }
        public int YearlyRewardEligibleCount { get; set; }

        // VIP Points System
        public double AverageVipPointsPerPlayer { get; set; }
        public int TotalVipPointsAwarded { get; set; }
    }

    /// <summary>
    /// Purchase Patterns Analytics ViewModel
    /// </summary>
    public class PurchasePatternsViewModel
    {
        public DateTime LastUpdated { get; set; } = DateTime.UtcNow;

        // Purchase Type Distribution
        public Dictionary<string, dynamic> PurchaseTypeDistribution { get; set; } = new();

        // Payment Method Distribution
        public Dictionary<string, dynamic> PaymentMethodDistribution { get; set; } = new();

        // Fraud Detection Metrics
        public int SuspiciousPurchaseCount { get; set; }
        public int HighRiskPurchaseCount { get; set; }
        public int VelocityFlaggedCount { get; set; }
        public int HighVelocityPlayers { get; set; }

        // Purchase Behavior
        public int FirstPurchaseCount { get; set; }
        public decimal AverageFirstPurchaseAmount { get; set; }
        public int RepeatPurchaserCount { get; set; }
        public double AverageDaysBetweenPurchases { get; set; }
    }

    /// <summary>
    /// Monetization Health Monitoring ViewModel
    /// </summary>
    public class MonetizationHealthViewModel
    {
        public DateTime LastUpdated { get; set; } = DateTime.UtcNow;

        // Customer Segmentation
        public int WhaleCount { get; set; }
        public int DolphinCount { get; set; }
        public int MinnowCount { get; set; }
        public int SpenderCount { get; set; }
        public int OccasionalCount { get; set; }
        public int F2PCount { get; set; }

        // Whale Health Metrics
        public decimal WhaleRevenueContribution { get; set; }
        public double WhaleRevenuePercentage { get; set; }
        public decimal AverageWhaleSpending { get; set; }

        // Spending Health
        public int HighVelocitySpenderCount { get; set; }
        public int ProblematicSpenderCount { get; set; }

        // Anti-Pay-to-Win Balance
        public double F2PEffectiveness { get; set; }
        public double SpendingInfluence { get; set; }
        public double BalanceScore { get; set; }
        public string BalanceStatus { get; set; } = string.Empty;
    }

    /// <summary>
    /// Chargeback Protection Analytics ViewModel
    /// </summary>
    public class ChargebackProtectionViewModel
    {
        public DateTime LastUpdated { get; set; } = DateTime.UtcNow;

        // Chargeback Statistics
        public int TotalChargebacks { get; set; }
        public int Chargebacks30d { get; set; }
        public double ChargebackRate { get; set; }
        public decimal ChargebackRevenueLost { get; set; }
        public decimal ChargebackFeesIncurred { get; set; }

        // Dispute Tracking
        public int ActiveDisputes { get; set; }
        public int DisputesWon { get; set; }
        public int DisputesLost { get; set; }
        public double DisputeWinRate { get; set; }

        // Risk Analysis
        public Dictionary<int, int> RiskScoreDistribution { get; set; } = new();
        public List<HighRiskTransactionData> HighRiskTransactions { get; set; } = new();
        public List<TrendDataPoint> ChargebackTrend { get; set; } = new();
    }

    /// <summary>
    /// Secret Tier Progression Data (KoA-inspired)
    /// </summary>
    public class SecretTierProgressionData
    {
        public int TierLevel { get; set; }
        public int UnlocksThisMonth { get; set; }
        public decimal AverageSpendToUnlock { get; set; }
    }

    /// <summary>
    /// VIP Progression Rate Data
    /// </summary>
    public class VipProgressionRate
    {
        public int FromTier { get; set; }
        public int ToTier { get; set; }
        public int ProgressionCount { get; set; }
        public double AverageTimeToProgress { get; set; }
    }

    /// <summary>
    /// High Risk Transaction Data
    /// </summary>
    public class HighRiskTransactionData
    {
        public string TransactionId { get; set; } = string.Empty;
        public int PlayerId { get; set; }
        public decimal Amount { get; set; }
        public int RiskScore { get; set; }
        public string RiskReason { get; set; } = string.Empty;
        public DateTime PurchaseDate { get; set; }
        public string Status { get; set; } = string.Empty;
    }

    #endregion

    #region Phase 6: System Health & Monitoring ViewModels - ADDED

    /// <summary>
    /// Main System Health Dashboard ViewModel
    /// </summary>
    public class SystemHealthViewModel
    {
        public DateTime LastUpdated { get; set; } = DateTime.UtcNow;

        // Overall Status
        public string OverallStatus { get; set; } = "HEALTHY"; // HEALTHY, WARNING, CRITICAL
        public double OverallHealthScore { get; set; }

        // System Uptime
        public int SystemUptimeDays { get; set; }
        public int SystemUptimeHours { get; set; }
        public int SystemUptimeMinutes { get; set; }
        public DateTime ProcessStartTime { get; set; }

        // Performance Metrics
        public double DatabaseResponseTimeMs { get; set; }
        public double ApiResponseTimeMs { get; set; }

        // Resource Usage
        public double CpuUsagePercent { get; set; }
        public double MemoryUsedMB { get; set; }
        public double MemoryPeakMB { get; set; }
        public double MemoryAvailableMB { get; set; }

        // Activity Metrics
        public int ActiveConnections { get; set; }
        public int ErrorCount24h { get; set; }
        public int ErrorCount7d { get; set; }
        public int ErrorCount30d { get; set; }

        // Database Metrics
        public int TotalDatabaseRecords { get; set; }
        public double DatabaseSizeEstimateMB { get; set; }

        // Component Health Checks
        public List<ComponentHealthCheck> ComponentHealth { get; set; } = new();

        // Recent Activity
        public List<SystemEvent> RecentSystemEvents { get; set; } = new();
    }

    /// <summary>
    /// Database Performance Monitoring ViewModel
    /// </summary>
    public class DatabasePerformanceViewModel
    {
        public DateTime LastUpdated { get; set; } = DateTime.UtcNow;

        // Query Performance Metrics
        public double AverageQueryTimeMs { get; set; }
        public double SlowestQueryTimeMs { get; set; }
        public double FastestQueryTimeMs { get; set; }

        // Table Sizes
        public Dictionary<string, int> TableSizes { get; set; } = new();
        public int TotalRecords { get; set; }

        // Growth Metrics
        public double CombatLogsGrowthRate { get; set; }
        public double PurchaseLogsGrowthRate { get; set; }

        // Database Size
        public double DatabaseSizeEstimateMB { get; set; }

        // Query Performance Details
        public List<QueryPerformanceMetric> QueryMetrics { get; set; } = new();

        // Connection Pool Status
        public string ConnectionPoolStatus { get; set; } = "HEALTHY";
        public int ActiveConnections { get; set; }
        public int IdleConnections { get; set; }

        // Slow Queries
        public List<SlowQueryInfo> SlowQueries { get; set; } = new();
    }

    /// <summary>
    /// API Performance Monitoring ViewModel
    /// </summary>
    public class ApiPerformanceViewModel
    {
        public DateTime LastUpdated { get; set; } = DateTime.UtcNow;

        // Request Metrics
        public int TotalRequests24h { get; set; }
        public int TotalRequests7d { get; set; }
        public double AverageRequestsPerHour { get; set; }
        public double AverageRequestsPerDay { get; set; }

        // Error Metrics
        public int ErrorCount24h { get; set; }
        public int ErrorCount7d { get; set; }
        public double ErrorRate24h { get; set; }
        public double ErrorRate7d { get; set; }

        // Performance Metrics
        public double AverageResponseTimeMs { get; set; }
        public double P95ResponseTimeMs { get; set; }
        public double P99ResponseTimeMs { get; set; }

        // Endpoint Usage
        public Dictionary<string, int> EndpointUsageDistribution { get; set; } = new();
        public string MostUsedEndpoint { get; set; } = string.Empty;

        // Rate Limiting
        public int RateLimitViolations24h { get; set; }

        // Failed Authentication
        public int FailedAuthAttempts24h { get; set; }
    }

    /// <summary>
    /// Server Resources Monitoring ViewModel
    /// </summary>
    public class ServerResourcesViewModel
    {
        public DateTime LastUpdated { get; set; } = DateTime.UtcNow;

        // CPU Metrics
        public double CurrentCpuUsagePercent { get; set; }
        public double AverageCpuUsagePercent { get; set; }
        public double PeakCpuUsagePercent { get; set; }
        public int CpuCoreCount { get; set; }

        // Memory Metrics
        public double CurrentMemoryUsageMB { get; set; }
        public double PeakMemoryUsageMB { get; set; }
        public double AvailableMemoryMB { get; set; }
        public double TotalMemoryMB { get; set; }
        public double MemoryUsagePercent { get; set; }

        // Disk Metrics
        public double DiskUsedGB { get; set; }
        public double DiskAvailableGB { get; set; }
        public double DiskTotalGB { get; set; }
        public double DiskUsagePercent { get; set; }

        // Network Metrics
        public double NetworkInboundMbps { get; set; }
        public double NetworkOutboundMbps { get; set; }

        // Process Metrics
        public int ThreadCount { get; set; }
        public int HandleCount { get; set; }
        public TimeSpan ProcessUptime { get; set; }

        // Platform Information
        public string OperatingSystem { get; set; } = string.Empty;
        public string RuntimeVersion { get; set; } = string.Empty;
        public string ProcessArchitecture { get; set; } = string.Empty;

        // Resource Trends
        public List<TrendDataPoint> CpuTrend { get; set; } = new();
        public List<TrendDataPoint> MemoryTrend { get; set; } = new();
    }

    /// <summary>
    /// Activity Feed ViewModel
    /// </summary>
    public class ActivityFeedViewModel
    {
        public DateTime LastUpdated { get; set; } = DateTime.UtcNow;
        public int CurrentPage { get; set; } = 1;
        public int PageSize { get; set; } = 50;
        public int TotalActivities { get; set; }
        public int TotalPages { get; set; }

        // Activities
        public List<ActivityFeedItem> Activities { get; set; } = new();

        // Activity Summary
        public int PlayerLoginsCount { get; set; }
        public int CombatEventsCount { get; set; }
        public int PurchaseEventsCount { get; set; }
        public int AdminActionsCount { get; set; }
    }

    /// <summary>
    /// Error Tracking ViewModel
    /// </summary>
    public class ErrorTrackingViewModel
    {
        public DateTime LastUpdated { get; set; } = DateTime.UtcNow;
        public int PeriodDays { get; set; } = 7;

        // Error Counts
        public int TotalErrors { get; set; }
        public int ErrorsToday { get; set; }
        public int ErrorsThisWeek { get; set; }

        // Error Distribution
        public Dictionary<string, int> ErrorsByType { get; set; } = new();
        public string MostCommonError { get; set; } = string.Empty;
        public int MostCommonErrorCount { get; set; }

        // Error Trend
        public List<TrendDataPoint> ErrorTrend { get; set; } = new();

        // Error Details
        public List<ErrorDetail> RecentErrors { get; set; } = new();

        // Error Rate
        public double ErrorRatePerHour { get; set; }
    }

    /// <summary>
    /// Component Health Check Result
    /// </summary>
    public class ComponentHealthCheck
    {
        public string Component { get; set; } = string.Empty;
        public string Status { get; set; } = string.Empty; // HEALTHY, DEGRADED, CRITICAL
        public string Message { get; set; } = string.Empty;
        public DateTime CheckTime { get; set; } = DateTime.UtcNow;
    }

    /// <summary>
    /// System Event Data
    /// </summary>
    public class SystemEvent
    {
        public DateTime Timestamp { get; set; } = DateTime.UtcNow;
        public string EventType { get; set; } = string.Empty;
        public string Description { get; set; } = string.Empty;
        public string Severity { get; set; } = "Info"; // Info, Warning, Danger
    }

    /// <summary>
    /// Query Performance Metric
    /// </summary>
    public class QueryPerformanceMetric
    {
        public string QueryType { get; set; } = string.Empty;
        public double ExecutionTime { get; set; }
        public int QueryCount { get; set; }
    }

    /// <summary>
    /// Activity Feed Item
    /// </summary>
    public class ActivityFeedItem
    {
        public DateTime Timestamp { get; set; } = DateTime.UtcNow;
        public string ActivityType { get; set; } = string.Empty;
        public string Description { get; set; } = string.Empty;
        public string Severity { get; set; } = "Info";
        public int? PlayerId { get; set; }
        public string? PlayerName { get; set; }
        public string? AdminUserId { get; set; }
    }

    /// <summary>
    /// Error Detail Data
    /// </summary>
    public class ErrorDetail
    {
        public int ErrorId { get; set; }
        public DateTime Timestamp { get; set; } = DateTime.UtcNow;
        public string ErrorType { get; set; } = string.Empty;
        public string ErrorMessage { get; set; } = string.Empty;
        public string StackTrace { get; set; } = string.Empty;
        public int? PlayerId { get; set; }
        public string? AdminUserId { get; set; }
        public string IpAddress { get; set; } = string.Empty;
        public string Severity { get; set; } = "Error"; // Error, Warning, Critical
    }

    #endregion

    #region Missing Service Models - ADDED TO FIX COMPILATION

    /// <summary>
    /// Kingdom merger recommendation model
    /// </summary>
    public class KingdomMergerRecommendationModel
    {
        public List<int> KingdomIds { get; set; } = new();
        public string RecommendationReason { get; set; } = string.Empty;
        public int Priority { get; set; }
        public Dictionary<string, object> MergerMetrics { get; set; } = new();
    }

    /// <summary>
    /// Revenue analytics model
    /// </summary>
    public class RevenueAnalyticsModel
    {
        public decimal TotalRevenue { get; set; }
        public decimal DailyAverageRevenue { get; set; }
        public List<TrendDataPoint> RevenueTrend { get; set; } = new();
        public Dictionary<string, decimal> RevenueByCategory { get; set; } = new();
    }

    /// <summary>
    /// Spending health model
    /// </summary>
    public class SpendingHealthModel
    {
        public int WhaleCount { get; set; }
        public int ProblematicSpendersCount { get; set; }
        public double AverageSpendingHealth { get; set; }
        public List<string> ProtectionMeasuresActive { get; set; } = new();
    }

    /// <summary>
    /// System monitoring view model
    /// </summary>
    public class SystemMonitoringViewModel
    {
        public SystemHealthModel SystemHealth { get; set; } = new();
        public DatabasePerformanceModel DatabasePerformance { get; set; } = new();
        public ApiPerformanceModel ApiPerformance { get; set; } = new();
        public ServerResourcesModel ServerResources { get; set; } = new();
    }

    /// <summary>
    /// Server resources model
    /// </summary>
    public class ServerResourcesModel
    {
        public double CpuUsage { get; set; }
        public double MemoryUsage { get; set; }
        public double DiskUsage { get; set; }
        public int ActiveConnections { get; set; }
        public double NetworkIO { get; set; }
        public DateTime LastUpdated { get; set; }
    }

    #endregion

    #region Utility Models

    /// <summary>
    /// Generic pagination model
    /// </summary>
    public class PaginationModel
    {
        public int CurrentPage { get; set; } = 1;
        public int TotalPages { get; set; }
        public int TotalItems { get; set; }
        public int ItemsPerPage { get; set; } = 25;
        public bool HasPrevious => CurrentPage > 1;
        public bool HasNext => CurrentPage < TotalPages;
    }

    /// <summary>
    /// Admin action result
    /// </summary>
    public class AdminActionResult
    {
        public bool Success { get; set; }
        public string Message { get; set; } = string.Empty;
        public Dictionary<string, object> Data { get; set; } = new();
        public List<string> Errors { get; set; } = new();
        public List<string> Warnings { get; set; } = new();
    }

    #endregion
}