using InABox.Configuration;
using InABox.Core;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace InABox.Database
{
    public class UserStore : Store<User>
    {
        public static TimeSpan PasswordExpirationTime { get; set; }

        protected override void BeforeSave(User entity)
        {
            base.BeforeSave(entity);

            if(entity.HasOriginalValue(x => x.Password))
            {
                if (DateTime.MaxValue - DateTime.Now < PasswordExpirationTime)
                {
                    entity.PasswordExpiration = DateTime.MaxValue;
                }
                else
                {
                    entity.PasswordExpiration = DateTime.UtcNow + PasswordExpirationTime;
                }
            }
        }
    }
}
