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

namespace e_suite.Service.Sentinel;

public class SentinelBase
{
    protected readonly IConfiguration Configuration;
    protected readonly IClock Clock;
    protected readonly ISentinelRepository SentinelRepository;

    public SentinelBase(IClock clock, IConfiguration configuration, ISentinelRepository sentinelRepository)
    {
        Clock = clock;
        Configuration = configuration;
        SentinelRepository = sentinelRepository;
    }

    protected (DateTimeOffset earliestAttemptTime, int maxLoginAttempts) GetLoginAttemptConstraints()
    {
        var loginAttemptTimeoutMinutes = Configuration.GetValue<int>("Sentinel:LoginAttemptTimeoutMinutes");
        var maxLoginAttempts = Configuration.GetValue<int>("Sentinel:MaxLoginAttempts");

        var earliestAttemptTime = Clock.GetNow.AddMinutes(-loginAttemptTimeoutMinutes);

        return (earliestAttemptTime, maxLoginAttempts);
    }
}