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

import net.cobem.grizzly.Grizzly;
import net.cobem.grizzly.communication.EventResponse;
import net.cobem.grizzly.habbohotel.rooms.Room;
import net.cobem.grizzly.habbohotel.sessions.Session;
import net.cobem.grizzly.habbohotel.users.User;
import net.cobem.grizzly.habbohotel.users.UserDAO;

public class SendRoomUserRightsComposer {
    public static EventResponse compose(Room mRoom) {
        EventResponse Message = new EventResponse();

        Message.Initialize(703);

        Message.addInt(mRoom.ID);
        Message.addInt(mRoom.getRightHolders().size());

        for (int UserID : mRoom.getRightHolders()) {

            if (Grizzly.getHabboHotel().getSessions().getByID(UserID) != null) {
                Session User = Grizzly.getHabboHotel().getSessions().getByID(UserID);

                Message.addInt(User.getHabbo().getID());
                Message.addString(User.getHabbo().getUsername());

            } else if(UserDAO.generateUser(UserID) != null) {
                User User = UserDAO.generateUser(UserID);

                Message.addInt(User.getID());
                Message.addString(User.getUsername());
            }
        }

        return Message;
    }
}
