using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 呼吸过滤器气雾直径测试仪
{
    internal class PasswordExpirationService
    {
        private readonly TimeSpan _maxExpirationPeriod;
        private readonly TimeSpan _reminderPeriod;

        public PasswordExpirationService()
        {
            // 读取配置文件中的密码时效策略
            var config = ConfigurationManager.AppSettings;
            _maxExpirationPeriod = TimeSpan.FromDays(int.Parse(config["MaxExpirationPeriodInDays"]));
            _reminderPeriod = TimeSpan.FromDays(int.Parse(config["ReminderPeriodInDays"]));
        }

        public bool IsPasswordExpired(DateTime passwordLastModified)
        {
            // 计算密码当前的有效期
            TimeSpan passwordExpirationPeriod = passwordLastModified + _maxExpirationPeriod - DateTime.Now;
            return passwordExpirationPeriod < TimeSpan.Zero;
        }

        public bool IsPasswordExpiringSoon(DateTime passwordLastModified)
        {
            // 判断密码是否接近过期提醒期
            TimeSpan passwordExpirationPeriod = passwordLastModified + _maxExpirationPeriod - DateTime.Now;
            return passwordExpirationPeriod < _reminderPeriod;
        }
    }
}
