/*
 * File: ShadowedRealms.Core/Models/Admin/AdminSession.cs
 * Created: 2025-11-01
 * Last Modified: 2025-11-01
 * Description: Entity model for admin session tracking
 * Last Edit Notes: Complete session model with login/logout tracking and security monitoring
 */

using System.ComponentModel.DataAnnotations;

namespace ShadowedRealms.Core.Models.Admin
{
    /// <summary>
    /// Tracks admin login sessions for security and audit purposes
    /// </summary>
    public class AdminSession
    {
        [Key]
        public long Id { get; set; }

        [Required]
        [MaxLength(450)]
        public int AdminUserId { get; set; }

        [Required]
        public DateTime LoginTime { get; set; } = DateTime.UtcNow;

        // Optional - set when admin logs out or session expires
        public DateTime? LogoutTime { get; set; }

        // IP address of login
        [MaxLength(45)]
        public string? IpAddress { get; set; }

        // User agent string
        [MaxLength(500)]
        public string? UserAgent { get; set; }

        // Location (if available from IP lookup)
        [MaxLength(200)]
        public string? Location { get; set; }

        // Session identifier
        public string? SessionId { get; set; }

        // Login method (password, 2FA, etc.)
        [MaxLength(50)]
        public string? LoginMethod { get; set; }

        // Risk assessment
        [MaxLength(20)]
        public string? RiskLevel { get; set; } = "Low"; // Low, Medium, High

        // Risk factors identified
        public string? RiskFactors { get; set; }

        // Device fingerprint (if available)
        public string? DeviceFingerprint { get; set; }

        // Session data (JSON)
        public string? SessionData { get; set; }

        // Was this session terminated forcibly?
        public bool ForcedLogout { get; set; } = false;

        // Reason for logout
        [MaxLength(200)]
        public string? LogoutReason { get; set; }

        // Actions performed during this session
        public int ActionsPerformed { get; set; } = 0;

        // Last activity timestamp
        public DateTime? LastActivity { get; set; }

        // Session duration in minutes (calculated on logout)
        public int? SessionDurationMinutes { get; set; }
    }
}