namespace OubHackMS.Users
{
    using OubHackMS.Core;
    using System;
    using System.Collections.Generic;

    internal class UserDB : LinkedClass
    {
        private List<User> activeUsers = new List<User>();

        public bool doLogin(string sUsername, string sPassword)
        {
            User item = new User(base.parent);
            if (item.setup(sUsername, sPassword))
            {
                this.activeUsers.Add(item);
                return true;
            }
            return false;
        }

        public void doLogout(User user)
        {
            if (this.activeUsers.Contains(user))
            {
                this.activeUsers.Remove(user);
            }
        }

        public User getByName(string sName)
        {
            foreach (User user in this.activeUsers)
            {
                if (user.sUsername == sName)
                {
                    return user;
                }
            }
            return null;
        }

        public User getBySessionID(long lSessionID)
        {
            foreach (User user in this.activeUsers)
            {
                if (user.lSessionID == lSessionID)
                {
                    return user;
                }
            }
            return null;
        }

        public User getBySteamID(long lSteamID)
        {
            foreach (User user in this.activeUsers)
            {
                if (user.lSteamID == lSteamID)
                {
                    return user;
                }
            }
            return null;
        }

        public bool isUserLoggedOn(long lSessionID)
        {
            foreach (User user in this.activeUsers)
            {
                if (user.lSessionID == lSessionID)
                {
                    return true;
                }
            }
            return false;
        }
    }
}

