using System.ComponentModel.DataAnnotations;

namespace AnsonBot.Core;

/// <summary>
/// One continuous period a player was connected to the server.
/// A session with a null <see cref="EndedUtc"/> is still open.
/// </summary>
public class PlaySession
{
    public int Id { get; set; }

    /// <summary>Stable identity for the player. Steam ID where available.</summary>
    [MaxLength(64)]
    public string PlayerId { get; set; } = "";

    /// <summary>Display name at the time of this session; players can rename.</summary>
    [MaxLength(128)]
    public string Name { get; set; } = "";

    public DateTime StartedUtc { get; set; }

    /// <summary>Null while the player is still online.</summary>
    public DateTime? EndedUtc { get; set; }

    /// <summary>
    /// Updated on every successful poll. If the bot dies without closing the
    /// session, this is the best available estimate of when the player left.
    /// </summary>
    public DateTime LastSeenUtc { get; set; }

    public TimeSpan Duration => (EndedUtc ?? DateTime.UtcNow) - StartedUtc;
}
