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

using Plus.Communication.Packets.Outgoing.Catalog;
using Plus.Core;
using Plus.HabboHotel.GameClients;
using Plus.Communication.Packets.Outgoing.Rooms.Notifications;

namespace Plus.HabboHotel.Rooms.Chat.Commands.Administrator
{
    class UpdateCommand : IChatCommand
    {
        public string PermissionRequired
        {
            get { return "command_update"; }
        }

        public string Parameters
        {
            get { return "%variable%"; }
        }

        public string Description
        {
            get { return "Rechargez une partie spécifique de l'hôtel."; }
        }

        public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {
            if (Params.Length == 1)
            {
                Session.SendWhisper("Vous devez inclure une chose à mettre à jour, exemple : :update catalogue");
                return;
            }

            string UpdateVariable = Params[1];
            switch (UpdateVariable.ToLower())
            {
                case "cata":
                case "catalog":
                case "catalogue":
                    {
                        if (!Session.GetHabbo().GetPermissions().HasCommand("command_update_catalog"))
                        {
                            Session.SendWhisper("Pas la permissions");
                            break;
                        }

                        PlusEnvironment.GetGame().GetCatalog().Init(PlusEnvironment.GetGame().GetItemManager());
                        PlusEnvironment.GetGame().GetClientManager().SendMessage(new CatalogUpdatedComposer());
                        Session.SendMessage(new BubbleNotificationComposer("Catalogue mise à jour!", "notif"));
                        break;
                    }

                case "items":
                case "furni":
                case "furniture":
                    {
                        if (!Session.GetHabbo().GetPermissions().HasCommand("command_update_furni"))
                        {
                            Session.SendWhisper("Pas la permissions.");
                            break;
                        }

                        PlusEnvironment.GetGame().GetItemManager().Init();
                        Session.SendMessage(new BubbleNotificationComposer("Furniture mise à jour!", "notif"));
                        break;
                    }

                case "models":
                    {
                        if (!Session.GetHabbo().GetPermissions().HasCommand("command_update_models"))
                        {
                            Session.SendWhisper("Pas la permissions");
                            break;
                        }

                        PlusEnvironment.GetGame().GetRoomManager().LoadModels();
                        Session.SendMessage(new BubbleNotificationComposer("Modèle d'appart mise à jour!", "notif"));
                        break;
                    }

                case "promotions":
                    {
                        if (!Session.GetHabbo().GetPermissions().HasCommand("command_update_promotions"))
                        {
                            Session.SendWhisper("Pas la permissions");
                            break;
                        }

                        PlusEnvironment.GetGame().GetLandingManager().LoadPromotions();
                        Session.SendMessage(new BubbleNotificationComposer("Promotions mise à jour!", "notif"));
                        break;
                    }

                case "youtube":
                    {
                        if (!Session.GetHabbo().GetPermissions().HasCommand("command_update_youtube"))
                        {
                            Session.SendWhisper("Pas la permissions");
                            break;
                        }

                        PlusEnvironment.GetGame().GetTelevisionManager().Init();
                        Session.SendMessage(new BubbleNotificationComposer("Youtube mise à jour!", "notif"));
                        break;
                    }

                case "filter":
                    {
                        if (!Session.GetHabbo().GetPermissions().HasCommand("command_update_filter"))
                        {
                            Session.SendWhisper("Pas la permissions");
                            break;
                        }

                        PlusEnvironment.GetGame().GetChatManager().GetFilter().Init();
                        Session.SendMessage(new BubbleNotificationComposer("Filtre mise à jour!", "notif"));
                        break;
                    }

                case "navigateur":
                    {
                        if (!Session.GetHabbo().GetPermissions().HasCommand("command_update_navigator"))
                        {
                            Session.SendWhisper("Pas la permissions");
                            break;
                        }

                        PlusEnvironment.GetGame().GetNavigator().Init();
                        Session.SendMessage(new BubbleNotificationComposer("Navigateur mise à jour!", "notif"));
                        break;
                    }

                case "ranks":
                case "rights":
                case "permissions":
                    {
                        if (!Session.GetHabbo().GetPermissions().HasCommand("command_update_rights"))
                        {
                            Session.SendWhisper("Pas la permissions");
                            break;
                        }

                        PlusEnvironment.GetGame().GetPermissionManager().Init();

                        foreach (GameClient Client in PlusEnvironment.GetGame().GetClientManager().GetClients.ToList())
                        {
                            if (Client == null || Client.GetHabbo() == null || Client.GetHabbo().GetPermissions() == null)
                                continue;

                            Client.GetHabbo().GetPermissions().Init(Client.GetHabbo());
                        }

                        Session.SendMessage(new BubbleNotificationComposer("Permissions mise à jour!", "notif"));
                        break;
                    }

                case "config":
                case "settings":
                    {
                        if (!Session.GetHabbo().GetPermissions().HasCommand("command_update_configuration"))
                        {
                            Session.SendWhisper("Pas la permissions");
                            break;
                        }

                        PlusEnvironment.ConfigData = new ConfigData();
                        Session.SendMessage(new BubbleNotificationComposer("Configuration mise à jour!", "notif"));
                        break;
                    }

                case "bans":
                    {
                        if (!Session.GetHabbo().GetPermissions().HasCommand("command_update_bans"))
                        {
                            Session.SendWhisper("Pas la permissions");
                            break;
                        }

                        PlusEnvironment.GetGame().GetModerationManager().ReCacheBans();
                        Session.SendMessage(new BubbleNotificationComposer("Banni mise à jour!", "notif"));
                        break;
                    }

                case "quests":
                    {
                        if (!Session.GetHabbo().GetPermissions().HasCommand("command_update_quests"))
                        {
                            Session.SendWhisper("Pas la permissions");
                            break;
                        }

                        PlusEnvironment.GetGame().GetQuestManager().Init();
                        Session.SendMessage(new BubbleNotificationComposer("Quest mise à jour!", "notif"));
                        break;
                    }

                case "achievements":
                    {
                        if (!Session.GetHabbo().GetPermissions().HasCommand("command_update_achievements"))
                        {
                            Session.SendWhisper("Pas la permissions");
                            break;
                        }

                        PlusEnvironment.GetGame().GetAchievementManager().LoadAchievements();
                        Session.SendMessage(new BubbleNotificationComposer("Achievement mise à jour!", "notif"));
                        break;
                    }

                case "moderation":
                    {
                        if (!Session.GetHabbo().GetPermissions().HasCommand("command_update_moderation"))
                        {
                            Session.SendWhisper("Pas la permissions");
                            break;
                        }

                        PlusEnvironment.GetGame().GetModerationManager().Init();
                        Session.SendMessage(new BubbleNotificationComposer("Modération mise à jour!", "notif"));
                        break;
                    }

                case "tickets":
                    {
                        if (!Session.GetHabbo().GetPermissions().HasCommand("command_update_tickets"))
                        {
                            Session.SendWhisper("Pas la permissions");
                            break;
                        }

                        if (PlusEnvironment.GetGame().GetModerationTool().Tickets.Count > 0)
                            PlusEnvironment.GetGame().GetModerationTool().Tickets.Clear();

                        Session.SendMessage(new BubbleNotificationComposer("Tickets mise à jour!", "notif"));
                        break;
                    }

                case "vouchers":
                    {
                        if (!Session.GetHabbo().GetPermissions().HasCommand("command_update_vouchers"))
                        {
                            Session.SendWhisper("Pas la permissions");
                            break;
                        }

                        PlusEnvironment.GetGame().GetCatalog().GetVoucherManager().Init();
                        Session.SendMessage(new BubbleNotificationComposer("Vouchers mise à jour!", "notif"));
                        break;
                    }

                case "gc":
                case "games":
                case "gamecenter":
                    {
                        if (!Session.GetHabbo().GetPermissions().HasCommand("command_update_game_center"))
                        {
                            Session.SendWhisper("Pas la permissions");
                            break;
                        }

                        PlusEnvironment.GetGame().GetGameDataManager().Init();
                        Session.SendMessage(new BubbleNotificationComposer("Game mise à jour!", "notif"));
                        break;
                    }

                case "pet_locale":
                    {
                        if (!Session.GetHabbo().GetPermissions().HasCommand("command_update_pet_locale"))
                        {
                            Session.SendWhisper("Pas la permissions");
                            break;
                        }

                        PlusEnvironment.GetGame().GetChatManager().GetPetLocale().Init();
                        Session.SendMessage(new BubbleNotificationComposer("Animaux mise à jour!", "notif"));
                        break;
                    }

                case "locale":
                    {
                        if (!Session.GetHabbo().GetPermissions().HasCommand("command_update_locale"))
                        {
                            Session.SendWhisper("Pas la permissions");
                            break;
                        }

                        PlusEnvironment.GetGame().GetLanguageLocale().Init();
                        Session.SendMessage(new BubbleNotificationComposer("Locale mise à jour!", "notif"));
                        break;
                    }

                case "mutant":
                    {
                        if (!Session.GetHabbo().GetPermissions().HasCommand("command_update_anti_mutant"))
                        {
                            Session.SendWhisper("Pas la permissions");
                            break;
                        }

                        PlusEnvironment.GetGame().GetAntiMutant().Init();
                        Session.SendMessage(new BubbleNotificationComposer("Anti Mutant mise à jour!", "notif"));
                        break;
                    }

                case "bots":
                    {
                        if (!Session.GetHabbo().GetPermissions().HasCommand("command_update_bots"))
                        {
                            Session.SendWhisper("Pas la permissions");
                            break;
                        }

                        PlusEnvironment.GetGame().GetBotManager().Init();
                        Session.SendMessage(new BubbleNotificationComposer("Bots mise à jour!", "notif"));
                        break;
                    }

                case "rewards":
                    {
                        if (!Session.GetHabbo().GetPermissions().HasCommand("command_update_rewards"))
                        {
                            Session.SendWhisper("Pas la permissions");
                            break;
                        }

                        PlusEnvironment.GetGame().GetRewardManager().Reload();
                        Session.SendMessage(new BubbleNotificationComposer("Rewards mise à jour!", "notif"));
                        break;
                    }

                case "chat_styles":
                    {
                        if (!Session.GetHabbo().GetPermissions().HasCommand("command_update_chat_styles"))
                        {
                            Session.SendWhisper("Pas la permissions");
                            break;
                        }

                        PlusEnvironment.GetGame().GetChatManager().GetChatStyles().Init();
                        Session.SendMessage(new BubbleNotificationComposer("Chat mise à jour!", "notif"));
                        break;
                    }

                case "badge_definitions":
                    {
                        if (!Session.GetHabbo().GetPermissions().HasCommand("command_update_badge_definitions"))
                        {
                            Session.SendWhisper("Pas la permissions");
                            break;
                        }

                        PlusEnvironment.GetGame().GetBadgeManager().Init();
                        Session.SendMessage(new BubbleNotificationComposer("Badge Definitions mise à jour!", "notif"));
                        break;
                    }

                default:
                    Session.SendWhisper("'" + UpdateVariable + "' N'est pas une chose valable pour recharger.");
                    break;
            }
        }
    }
}
