// Copyright © 2017-2018 Atomic Software, LLC. All Rights Reserved.
// See LICENSE.md for full license information.

using Atom.Core.Collections;
using Atom.Core.Game;
using Atom.Core.SQL;

namespace Atom.LoginServer.Services
{
    internal static class AccountService
    {
        internal static Dictionary<string, Account> CachedAccounts = new Dictionary<string,Account>();

        internal static void Login(string sUserName, string sPassword, out int userNo, out int blocked, out int canLogin)
        {
            // Build the SQL Query.
            using (var p_User_Login = new StoredProcedure("p_User_Login", Program.ServerInstance.ODBCConnection))
            {
                p_User_Login.AddParameter("userID", sUserName, 20);
                p_User_Login.AddParameter("userPW", sPassword, 32);

                // Declare output variable types.
                p_User_Login.AddOutput<int>("userNo");
                p_User_Login.AddOutput<byte>("authID");
                p_User_Login.AddOutput<int>("block");
                p_User_Login.AddOutput<int>("canLogin");

                p_User_Login.Run(); // Run the query.

                // Get the value of the output variables.
                userNo = p_User_Login.GetOutput<int>("userNo");
                p_User_Login.GetOutput<byte>("authID"); // This variable is not used, so we don't assign it to anything.
                blocked = p_User_Login.GetOutput<int>("block");
                canLogin = p_User_Login.GetOutput<int>("canLogin");
            }
        }
    }
}
