package net.cobem.grizzly.communication.composers.stream;

import net.cobem.grizzly.Grizzly;
import net.cobem.grizzly.communication.EventResponse;
import net.cobem.grizzly.communication.HeaderLibrary;
import net.cobem.grizzly.habbohotel.stream.StreamObject;
import net.cobem.grizzly.habbohotel.users.User;
import net.cobem.grizzly.habbohotel.users.UserDAO;

import java.util.List;

public class InitializeFriendStreamComposer {
    public static EventResponse compose() {
        EventResponse Message = new EventResponse();

        Message.Initialize(HeaderLibrary.InitializeFriendStreamEvent);

        List<StreamObject> Regular = Grizzly.getHabboHotel().getStream().getRegular();
        List<StreamObject> Official = Grizzly.getHabboHotel().getStream().getOfficial();

        Message.addInt(Regular.size() + Official.size()); //count

        for (StreamObject Obj : Regular) {
            Message.addInt(Obj.ID); //message ID
            Message.addInt(Obj.Type); //type id
            Message.addString(Obj.getUser().getID()); //message as string
            Message.addString(Obj.getUser().getUsername());
            Message.addString(Obj.getUser().getGender().toString().toLowerCase());
            Message.addString("http://localhost/Storage/Heads/look.gif?figure=" + Obj.getUser().getLook() + ".gif");
            Message.addInt(Obj.getMinutesFrom()); //time ago

            if (Obj.Type == 0) {
                Message.addInt(5);
                Message.addInt(Obj.Likes); //likes
                Message.addBool(true);
                Message.addBool(true);
                Message.addBool(false);
                User Friend = UserDAO.generateUser(new Integer(Obj.Message));
                Message.addString(Friend.getID());
                Message.addString(Friend.getUsername());
            }

            if (Obj.Type == 3) {
                Message.addInt(4);
                Message.addInt(Obj.Likes); //likes
                Message.addBool(true);
                Message.addBool(true);
                Message.addBool(false);
                Message.addString(Obj.getUser().getMotto());
            }

            if (Obj.Type == 5) {
                Message.addInt(1);
                Message.addInt(Obj.Likes); //likes
                Message.addBool(true);
                Message.addBool(true);
                Message.addBool(false);
                Message.addString(Obj.Message);
            }
        }

        for (StreamObject Obj : Official) {
            Message.addInt(Obj.ID); //message ID
            Message.addInt(4); //type id
            Message.addString(Obj.ID); //message as string
            Message.addString("");
            Message.addString("");
            Message.addString("");
            Message.addInt(Obj.getMinutesFrom()); //time ago
            Message.addInt(6);
            Message.addInt(Obj.Likes); //likes
            Message.addBool(true);
            Message.addBool(true);
            Message.addBool(false);
            Message.addString(Obj.Message);
            Message.addString("#");
        }
        return Message;
    }
}
