using Data.SeaHavenIndustries; using Microsoft.EntityFrameworkCore; using SeaHaven.DataServices.Interfaces; namespace SeaHaven.DataServices.Implementation { public class WorkOrderOpsHealthDataService : IWorkOrderOpsHealthDataService { private readonly ApplicationDbContext _context; public WorkOrderOpsHealthDataService(ApplicationDbContext context) { _context = context; } public Task CountSyncRejectedSinceAsync(DateTime since, CancellationToken cancellationToken) => _context.WorkOrderAuditLogs .CountAsync(l => l.Action == "SyncRejected" && l.CreatedAt >= since, cancellationToken); public Task CountFieldLocksAsync(CancellationToken cancellationToken) => _context.WorkOrderFieldLocks.CountAsync(cancellationToken); public async Task GetLastWeekRolledProcessedAtAsync(CancellationToken cancellationToken) { if (!await _context.WorkOrderWeekRolledLedgers.AnyAsync(cancellationToken)) return null; return await _context.WorkOrderWeekRolledLedgers .MaxAsync(l => (DateTime?)l.ProcessedAt, cancellationToken); } } }