using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;

namespace StellaOps.Authority.Storage.Mongo.Documents;

/// <summary>
/// Represents a recorded login attempt for audit and lockout purposes.
/// </summary>
[BsonIgnoreExtraElements]
public sealed class AuthorityLoginAttemptDocument
{
    [BsonId]
    [BsonRepresentation(BsonType.ObjectId)]
    public string Id { get; set; } = ObjectId.GenerateNewId().ToString();

    [BsonElement("subjectId")]
    [BsonIgnoreIfNull]
    public string? SubjectId { get; set; }

    [BsonElement("username")]
    [BsonIgnoreIfNull]
    public string? Username { get; set; }

    [BsonElement("clientId")]
    [BsonIgnoreIfNull]
    public string? ClientId { get; set; }

    [BsonElement("plugin")]
    [BsonIgnoreIfNull]
    public string? Plugin { get; set; }

    [BsonElement("successful")]
    public bool Successful { get; set; }

    [BsonElement("reason")]
    [BsonIgnoreIfNull]
    public string? Reason { get; set; }

    [BsonElement("remoteAddress")]
    [BsonIgnoreIfNull]
    public string? RemoteAddress { get; set; }

    [BsonElement("occurredAt")]
    public DateTimeOffset OccurredAt { get; set; } = DateTimeOffset.UtcNow;
}
