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

using Plus.HabboHotel.Rooms;
using Plus.HabboHotel.Pathfinding;
using Plus.HabboHotel.GameClients;
using Plus.Communication.Packets.Outgoing.Rooms.Chat;
using Plus.Communication.Packets.Outgoing.Rooms.Notifications;
using Plus.Communication.Packets.Outgoing.Inventory.Purse;

namespace Plus.HabboHotel.Rooms.Chat.Commands.Events
{
    class PremiarCommand : IChatCommand
    {
        public string PermissionRequired
        {
            get { return "command_give"; }
        }

        public string Parameters
        {
            get { return "%username% %badge%"; }
        }

        public string Description
        {
            get { return "Faz todas as funçoes para finaliza um evento."; }
        }

        public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {
            if (Params.Length == 1)
            {
                Session.SendWhisper("Por favor, digite o usuário que deseja premiar!");
                return;
            }

            GameClient Target = PlusEnvironment.GetGame().GetClientManager().GetClientByUsername(Params[1]);
            if (Target == null)
            {
                Session.SendWhisper("Opa, não foi possível encontrar esse usuário!");
                return;
            }

            RoomUser TargetUser = Room.GetRoomUserManager().GetRoomUserByHabbo(Target.GetHabbo().Id);
            if (TargetUser == null)
            {
                Session.SendWhisper("Usuário não encontrado! Talvez ele não esteja online ou nesta sala.");
                return;
            }

            if (Target.GetHabbo().Username == Session.GetHabbo().Username)
            {
                Session.SendWhisper("Você não pode se premiar!");
                return;
            }

            if (Params.Length != 3)
            {
                Session.SendWhisper("Por favor, indique o código do emblema que gostaria de dar!");
                return;
            }



            RoomUser ThisUser = Room.GetRoomUserManager().GetRoomUserByHabbo(Session.GetHabbo().Id);
            if (ThisUser == null)
            {
                return;
            }
            else
            {
                PlusEnvironment.GetGame().GetClientManager().SendMessage(new RoomNotificationComposer("rank", "message", "O usuário " + TargetUser.GetUsername() + " ganhou o evento!    Parabéns"));
                Target.GetHabbo().Credits = Target.GetHabbo().Credits += 5;
                Target.SendMessage(new CreditBalanceComposer(Target.GetHabbo().Credits));
                if (Session.GetHabbo().Id != Session.GetHabbo().Id)
                    Target.SendWhisper("Parabens você ganhou um evento! No Habbriol");
                Session.SendWhisper("Concedido com sucesso " + 5 + " Credito(s) ao " + Target.GetHabbo().Username + "!");
                Target.SendMessage(new RoomNotificationComposer("goldapple", "message", "Você ganhou " + 5 + " Credito(s) parabens " + Target.GetHabbo().Username + "!"));

                Target.GetHabbo().Duckets += 50;
                Target.SendMessage(new HabboActivityPointNotificationComposer(Target.GetHabbo().Duckets, 5));
                if (Target.GetHabbo().Id != Session.GetHabbo().Id)
                    Session.SendWhisper("Concedido com sucesso " + 5 + " Ducket(s) ao " + Target.GetHabbo().Username + "!");
                Target.SendMessage(new RoomNotificationComposer("coracao2", "message", "Você ganhou " + 5 + " Ducket(s)! parabens " + Target.GetHabbo().Username + "!"));

                Target.GetHabbo().Diamonds += 3;
                Target.SendMessage(new HabboActivityPointNotificationComposer(Target.GetHabbo().Diamonds, 5, 5));
                if (Target.GetHabbo().Id != Session.GetHabbo().Id)
                    Session.SendWhisper("Concedido com sucesso " + 3 + " Diamantes ao " + Target.GetHabbo().Username + "!");

                Target.GetHabbo().GOTWPoints = Target.GetHabbo().GOTWPoints + 1;
                Target.SendMessage(new HabboActivityPointNotificationComposer(Target.GetHabbo().GOTWPoints, 1, 103));
                if (Target.GetHabbo().Id != Session.GetHabbo().Id)
                    Session.SendWhisper("Concedido com sucesso " + 1 + " Ponto de Evento ao " + Target.GetHabbo().Username + "!");
                Target.SendMessage(new RoomNotificationComposer("control", "message", "Você ganhou " + 1 + " Ponto de Evento! parabens " + Target.GetHabbo().Username + "!"));

                if (!Target.GetHabbo().GetBadgeComponent().HasBadge(Params[2]))
                {
                    Target.GetHabbo().GetBadgeComponent().GiveBadge(Params[2], true, Target);
                    if (Target.GetHabbo().Id != Session.GetHabbo().Id)
                        Target.SendMessage(new RoomNotificationComposer("game", "message", "Você acaba de receber um emblema!"));
                }
                else
                    Session.SendWhisper("Uau, esse usuário já possui este emblema (" + Params[2] + ") !");

                foreach (RoomUser RoomUser in Room.GetRoomUserManager().GetUserList().ToList())

                    Session.SendWhisper("Você deu com sucesso emblema " + Params[2] + "!");
            }
        }

        private void SendMessage(RoomNotificationComposer roomNotificationComposer)
        {
            throw new NotImplementedException();
        }
    }
}