using e_suite.API.Common.repository;
using eSuite.Core.Clock;
using Microsoft.Extensions.Configuration;

namespace e_suite.Service.Sentinel;

public class SentinelMaintenance : SentinelBase, ISentinelMaintenance
{
    public SentinelMaintenance(IClock clock, IConfiguration configuration, ISentinelRepository sentinelRepository) : base(clock, configuration, sentinelRepository)
    {
    }

    [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0059:Unnecessary assignment of a value", Justification = "Leaving the variable name is clearer")]
    public async Task ClearOldSentinelData()
    {
        var (earliestAttemptTime, maxLoginAttempts) = GetLoginAttemptConstraints();

        await SentinelRepository.DeleteAccessAttemptsBefore(earliestAttemptTime);
    }
}