package cs451.net.event;

import cs451.parser.Host;

/**
 * NetEvent abstraction class
 *
 * Holds a {@link cs451.net.event.Message} and a {@link cs451.parser.Host}
 *
 * @author C. Hölzl
 */
public class NetEvent {

    public final Host peer;
    public final Message message;

    private NetEvent(Host peer, Message message) {
        this.peer = peer;
        this.message = message;
    }


    public static NetEvent Message(Host peer, Integer mess_id){
        return new NetEvent(peer, Message.DMSG(mess_id));
    }

    public static NetEvent Message(Host peer, Integer mess_id, Message.TYPE tpe){
        return new NetEvent(peer, Message.TMSG(mess_id,tpe));
    }

    public static NetEvent Message(Host peer, Message m){
        return new NetEvent(peer, Message.MSG(m));
    }

    public static NetEvent Message(Message m){
        return new NetEvent(NO_PEER,Message.MSG(m));
    }

    public static NetEvent Message(Integer mess_id){
        return new NetEvent(NO_PEER, Message.DMSG(mess_id));
    }

    public static NetEvent Message(Integer src, Integer mess_id) {
        return new NetEvent(NO_PEER, Message.DMSG(mess_id,src));
    }

    public static NetEvent MessageACK(Host peer, Message message) {
        NetEvent ne = NetEvent.Message(peer,message);
        ne.message.tpe = Message.TYPE.ACK;
        return ne;
    }

    public static NetEvent MessageHRTB(Host peer){
        return NetEvent.Message(peer,Message.HRTB());
    }


    public static NetEvent EMPTY(){
        return new NetEvent(NO_PEER, Message.EMPTY());
    }

    public static final Host NO_PEER = null;
}