using e_suite.API.Common.repository;
using e_suite.Database.Audit;
using e_suite.Database.Core.Tables.Sentinel;
using e_suite.UnitTestCore;
using MockQueryable;

namespace e_suite.Modules.BlockedIPsManager.UnitTests.Repository;

public class FakeBlockedIPsManagerRepository : FakeRepository, IBlockedIPsManagerRepository
{
    public string IpAddress = string.Empty;
    public DateTimeOffset EarliestAttemptTime = DateTimeOffset.MinValue;
    public List<FailedAccessAttempt> FailedAccessAttempts = [];

    public IQueryable<FailedAccessAttempt> GetBlockedIPs(DateTimeOffset earliestAttemptTime)
    {
        return FailedAccessAttempts.BuildMock();
    }

    public Task UnBlockIP(AuditUserDetails auditUserDetails, string ipAddress, CancellationToken cancellationToken)
    {
        var failedAccessAttempt = FailedAccessAttempts.Where(i => i.IPAddress == ipAddress).First();
        
        var removed = FailedAccessAttempts.Remove(failedAccessAttempt);
        return Task.CompletedTask;
    }
}
