package com.atlassian.stash.internal.topic;

import com.atlassian.bitbucket.cluster.ClusterNode;
import com.atlassian.bitbucket.topic.MessageEvent;

import javax.annotation.Nonnull;
import java.util.Date;

public class DefaultMessageEvent<T> implements MessageEvent<T> {

    private final T message;
    private final ClusterNode source;
    private final long timestamp;
    private final String topic;

    public DefaultMessageEvent(ClusterNode source, long timestamp, String topic, T message) {
        this.message = message;
        this.source = source;
        this.timestamp = timestamp;
        this.topic = topic;
    }

    @Nonnull
    @Override
    public T getMessage() {
        return message;
    }

    @Nonnull
    @Override
    public String getTopic() {
        return topic;
    }

    @Nonnull
    @Override
    public Date getPublishTime() {
        return new Date(timestamp);
    }

    @Nonnull
    @Override
    public ClusterNode getSource() {
        return source;
    }
}
