using System;
using System.Linq;
using System.Text;
using System.Data;
using System.Collections.Generic;
using Plus.Communication.Packets.Outgoing.Notifications;
using System.Text.RegularExpressions;
using Plus.Database.Interfaces;
using Plus.HabboHotel.GameClients;
using Plus.Communication.Packets.Outgoing.Rooms.Notifications;

namespace Plus.HabboHotel.Rooms.Chat.Filter
{
    public sealed class UserdevManager
    {
        private List<Userdev> _user;

        public UserdevManager()
        {
            this._user = new List<Userdev>();
        }

        public void Init()
        {
            if (this._user.Count > 0)
                this._user.Clear();

            DataTable Data = null;
            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery("SELECT * FROM `users`");
                Data = dbClient.getTable();

                if (Data != null)
                {
                    foreach (DataRow Row in Data.Rows)
                    {
                        this._user.Add(new Userdev(Convert.ToString(Row["username"])));
                    }
                }
            }
        }
        public string CheckNotif(string Message, GameClient Session)
        {
            foreach (Userdev Filter in this._user.ToList())
            {
                if (Message.Contains(Filter.Username) && Filter.Username != Session.GetHabbo().Username)
                {
                    GameClient TargetClient = PlusEnvironment.GetGame().GetClientManager().GetClientByUsername(Filter.Username);

                    Message = Regex.Replace(Message, Filter.Username, Filter.Username, RegexOptions.IgnoreCase);
                    if (Session.GetHabbo().CurrentRoomId != TargetClient.GetHabbo().CurrentRoomId)
                    {
                        if(TargetClient.GetHabbo().Identifier == 0)
                        TargetClient.SendMessage(RoomNotificationComposer.SendBubble("notif", Session.GetHabbo().Username + " Ta identifier, clique ici pour le rejoindre !", "event:navigator/goto/" + Session.GetHabbo().CurrentRoom.RoomId + ""));
                    } else
                    {
                        if (TargetClient.GetHabbo().Identifier == 0)
                        TargetClient.SendMessage(RoomNotificationComposer.SendBubble("notif", Session.GetHabbo().Username + " Ta identifier, dans l'appart où tu te situes !", ""));
                        
                    }
                }
                else
                {
                    continue;
                }
            }

            return Message.TrimEnd(' ');
        }

    }
}
