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

using Atom.Core.Collections;
using Atom.Core.Extensions;
using Atom.Core.Local;
using Atom.Core.Networking;
using Atom.Core.Networking.Messages.Structures.Local;
using Atom.Core.Networking.Messages.Structures.User;
using Atom.Core.Platform;

namespace Atom.LoginServer.Services
{
    internal static class TransferService
    {
        private static readonly Dictionary<string, long> ActiveTransfers = new Dictionary<string, long>();

        internal static void AddTransfer(string validate_new)
        {
            if (ActiveTransfers.ContainsKey(validate_new))
            {
                return;
            }

            ActiveTransfers.Add(validate_new, SystemTime.Milliseconds());
        }

        internal static Dictionary<string, long> GetTransfers()
        {
            return ActiveTransfers;
        }

        internal static void TransferClientToWM(Client client, World worldManager)
        {
            var UsernameHash = client.Account.Username.ToMD5();

            AccountService.CachedAccounts.Add(UsernameHash, client.Account);

            new PROTO_NC_LOCAL_ADDTRANSFER_CMD(UsernameHash).SendLocal(worldManager.Client);
            new PROTO_NC_USER_WORLDSELECT_ACK(worldManager.Status, worldManager.IPAddress, (ushort) worldManager.Port, UsernameHash).Send(client);
        }
    }
}
