using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CollaborativePlatformProject.CollaborationPlatform.Entity;

namespace CollaborativePlatformProject.CollaborationPlatform.Util
{
    /// <summary>
    ///
    /// <para>⽂件名(File Name):    LoginUtil.cs</para>
    ///
    /// <para>描述(Description):    登陆工具类</para>
    ///
    /// <para>数据表(Tables):       nothing</para>
    ///
    /// <para>作者(Author):         Sun Zheng Ji</para>
    ///
    /// <para>⽇期(Create Date):     2024年4月12日13:37:</para>
    ///
    /// 修改记录(Revision History):
    ///     R1:
    ///         修改作者:
    ///         修改⽇期:
    ///         修改理由:
    ///
    /// </summary>
    public class LoginUtil
    {
        /// <summary>
        /// 用户名和密码
        /// </summary>
        public static List<UserInformationEntity> UserInfos = new List<UserInformationEntity>(){new UserInformationEntity("1","1")};

        /// <summary>
        /// 验证登陆
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public static bool VerifyLoginMethod(string userName, string pwd)
        {
            bool success = false;

            foreach (var userInfo in UserInfos)
            {
                if (userInfo.UserName.Equals(userName) && userInfo.UserPwd.Equals(pwd))
                {
                    success = true;
                    break;
                }
            }

            return success;
        }

        /// <summary>
        /// 注册
        /// </summary>
        /// <returns></returns>
        public static bool RegisterMethod(string userName, string pwd)
        {
            try
            {
                UserInfos.Add(new UserInformationEntity(userName, pwd));
            }
            catch (Exception e)
            {
                return false;
            }

            return true;
        }
    }
}