using FastBlog.Core.Models.Users;

namespace FastBlog.Core.Options;

public class SessionOptions
{
    public int SlidingExpirationSeconds { get; set; }
    public int AbsoluteExpirationSeconds { get; set; }
    public bool EnableAbsoluteExpiration { get; set; }
    public bool EnableSlidingExpiration { get; set; }
    
    public int TouchAfterSeconds { get; set; }

    public (bool SlidingValid, bool AbsoluteValid) Validate(Session session)
    {
        (bool slidingValid, bool absoluteValid) = (true, true);

        if (EnableAbsoluteExpiration)
            slidingValid = session.CreatedAt.AddSeconds(AbsoluteExpirationSeconds) > DateTime.UtcNow;

        if (EnableSlidingExpiration)
            absoluteValid = session.LastUsed.AddSeconds(SlidingExpirationSeconds) > DateTime.UtcNow;
        
        return (slidingValid, absoluteValid);
    }
}