using Plus.Communication.Packets.Outgoing.Groups;
using Plus.HabboHotel.GameClients;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Plus.Communication.Packets.Incoming.Groups
{
    class PostGroupContentEvent : IPacketEvent
    {
        public void Parse(GameClient Session, ClientPacket Packet)
        {
            var ForumId = Packet.PopInt();
            var ThreadId = Packet.PopInt();
            var Caption = Packet.PopString();
            var Message = Packet.PopString();

            var Forum = PlusEnvironment.GetGame().GetGroupForumManager().GetForum(ForumId);
            if (Forum == null)
            {
                Session.SendNotification("Oops le forum n'existe pas!");
                return;
            }

            var IsNewThread = ThreadId == 0;
            if (IsNewThread)
            {
                var Thread = Forum.CreateThread(Session.GetHabbo().Id, Caption, Session);
                var Post = Thread.CreatePost(Session.GetHabbo().Id, Message, Session);

                Session.SendMessage(new ThreadCreatedComposer(Session, Thread));
                //Session.SendMessage(new PostUpdatedComposer(Session, Post));
                // Session.SendMessage(new ThreadReplyComposer(Session, Post));

            }
            else
            {
                var Thread = Forum.GetThread(ThreadId);
                if (Thread == null)
                {
                    Session.SendNotification("Opss!.. Forum Discussion n'existe pas!");
                    return;
                }

                var Post = Thread.CreatePost(Session.GetHabbo().Id, Message, Session);
                Session.SendMessage(new ThreadReplyComposer(Session, Post));
            }


        }
    }
}
