using Microsoft.EntityFrameworkCore;
using ZB.MOM.WW.OtOpcUa.Configuration;
using ZB.MOM.WW.OtOpcUa.Configuration.Entities;

namespace ZB.MOM.WW.OtOpcUa.Admin.Services;

public sealed class AuditLogService(OtOpcUaConfigDbContext db)
{
    public Task<List<ConfigAuditLog>> ListRecentAsync(string? clusterId, int limit, CancellationToken ct)
    {
        var q = db.ConfigAuditLogs.AsNoTracking();
        if (clusterId is not null) q = q.Where(a => a.ClusterId == clusterId);
        return q.OrderByDescending(a => a.Timestamp).Take(limit).ToListAsync(ct);
    }
}
