using Titano.Core.Model; using Titano.Data; namespace Titano.Server.Security; /// Appends who did what to the audit log (BRIEF ยง14.2): sign-ins, user, sequence, archive and setting changes. public sealed class AuditLog(TitanoDatabase db, TimeProvider time) { public Task WriteAsync(Caller caller, HttpContext context, string action, string? targetKind = null, string? targetId = null, string? details = null) => WriteAsync(caller.Id, caller.User.Username, context, action, targetKind, targetId, details); public Task WriteAsync(Guid? userId, string? username, HttpContext? context, string action, string? targetKind = null, string? targetId = null, string? details = null) => db.Audit.AppendAsync(new AuditEntry { Id = Guid.CreateVersion7(), At = time.GetUtcNow(), UserId = userId, Username = username, Action = action, TargetKind = targetKind, TargetId = targetId, Details = details, RemoteAddress = context?.Connection.RemoteIpAddress?.ToString(), }); }