using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

using Plus.HabboHotel.GameClients;
using Plus.Communication.Packets.Outgoing.Inventory.Purse;
using Plus.Communication.Packets.Outgoing.Rooms.Notifications;
using Plus.Database.Interfaces;

namespace Plus.HabboHotel.Rooms.Chat.Commands.Moderator
{
    class SkillCommand : IChatCommand
    {
        public string PermissionRequired
        {
            get { return "command_giveskill"; }
        }

        public string Parameters
        {
            get { return "%username% %type% %montant%"; }
        }

        public string Description
        {
            get { return ""; }
        }

        public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {
            if (Params.Length == 1)
            {
                Session.SendWhisper("Veuillez saisir un type de devise! (comp_jeu, comp_architecture, comp_look, comp_fidelite, comp_popularite).");
                return;
            }

            GameClient Target = PlusEnvironment.GetGame().GetClientManager().GetClientByUsername(Params[1]);
            if (Target == null)
            {
                Session.SendWhisper("Oups, nous n'avons pas pu trouver cet utilisateur!");
                return;
            }

            string UpdateVal = Params[2];
            switch (UpdateVal.ToLower())
            {
                case "comp_jeu":
                case "jeu":
                    {
                        int Amount;
                        if (int.TryParse(Params[3], out Amount))
                        {
                            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
                            {
                                dbClient.SetQuery("UPDATE `users` SET `comp_jeu` = comp_jeu + @montant WHERE id = @id LIMIT 1;");
                                dbClient.AddParameter("montant", Amount);
                                dbClient.AddParameter("id", Target.GetHabbo().Id);
                                dbClient.RunQuery();
                            }
                            if (Target.GetHabbo().Id != Session.GetHabbo().Id)
                            Session.SendMessage(new BubbleNotificationComposer("Envoyer avec succès.", "notif"));
                            break;
                        }
                        else
                        {
                            Session.SendWhisper("Montant invalide");
                            break;
                        }

                    }

                case "comp_architecture":
                case "architecture":
                    {
                        int Amount;
                        if (int.TryParse(Params[3], out Amount))
                        {
                            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
                            {
                                dbClient.SetQuery("UPDATE `users` SET `comp_architecture` = comp_architecture + @montant WHERE id = @id LIMIT 1;");
                                dbClient.AddParameter("montant", Amount);
                                dbClient.AddParameter("id", Target.GetHabbo().Id);
                                dbClient.RunQuery();
                            }
                            if (Target.GetHabbo().Id != Session.GetHabbo().Id)
                                Session.SendMessage(new BubbleNotificationComposer("Envoyer avec succès.", "notif"));
                            break;
                        }
                        else
                        {
                            Session.SendWhisper("Montant invalide");
                            break;
                        }
                    }



                case "comp_look":
                case "look":
                    {
                        int Amount;
                        if (int.TryParse(Params[3], out Amount))
                        {
                            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
                            {
                                dbClient.SetQuery("UPDATE `users` SET `comp_look` = comp_look + @montant WHERE id = @id LIMIT 1;");
                                dbClient.AddParameter("montant", Amount);
                                dbClient.AddParameter("id", Target.GetHabbo().Id);
                                dbClient.RunQuery();
                            }
                            if (Target.GetHabbo().Id != Session.GetHabbo().Id)
                                Session.SendMessage(new BubbleNotificationComposer("Envoyer avec succès.", "notif"));
                            break;
                        }
                        else
                        {
                            Session.SendWhisper("Montant invalide");
                            break;
                        }
                    }

                case "comp_fidelite":
                case "fidelite":
                    {
                        int Amount;
                        if (int.TryParse(Params[3], out Amount))
                        {
                            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
                            {
                                dbClient.SetQuery("UPDATE `users` SET `comp_fidelite` = comp_fidelite + @montant WHERE id = @id LIMIT 1;");
                                dbClient.AddParameter("montant", Amount);
                                dbClient.AddParameter("id", Target.GetHabbo().Id);
                                dbClient.RunQuery();
                            }
                            if (Target.GetHabbo().Id != Session.GetHabbo().Id)
                                Session.SendMessage(new BubbleNotificationComposer("Envoyer avec succès.", "notif"));
                            break;
                        }
                        else
                        {
                            Session.SendWhisper("Montant invalide");
                            break;
                        }
                    }

                case "comp_popularite":
                case "popularite":
                    {
                        int Amount;
                        if (int.TryParse(Params[3], out Amount))
                        {
                            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
                            {
                                dbClient.SetQuery("UPDATE `users` SET `comp_popularite` = comp_popularite + @montant WHERE id = @id LIMIT 1;");
                                dbClient.AddParameter("montant", Amount);
                                dbClient.AddParameter("id", Target.GetHabbo().Id);
                                dbClient.RunQuery();
                            }
                            if (Target.GetHabbo().Id != Session.GetHabbo().Id)
                                Session.SendMessage(new BubbleNotificationComposer("Envoyer avec succès.", "notif"));
                            break;
                        }
                        else
                        {
                            Session.SendWhisper("Montant invalide");
                            break;
                        }
                    }
                default:
                    Session.SendWhisper("'" + UpdateVal + "' n'est pas une valeur correct!");
                    break;
            }
        }
    }
}