package com.atlassian.stash.internal.comment.like.notification;

import com.atlassian.bitbucket.comment.Comment;
import com.atlassian.bitbucket.user.ApplicationUser;

import javax.annotation.Nonnull;
import java.util.Collection;
import java.util.Date;
import java.util.LinkedHashSet;
import java.util.Set;

import static com.google.common.base.Preconditions.checkNotNull;

/**
 * Metadata to render a like notification.
 */
class CommentLikeData {

    private final Comment comment;
    private final Set<ApplicationUser> likers;
    private Date date;

    public CommentLikeData(@Nonnull Comment comment) {
        this.comment = checkNotNull(comment, "comment");
        this.date = new Date();
        this.likers = new LinkedHashSet<>();
    }

    public void addLike(@Nonnull ApplicationUser liker, @Nonnull Date date) {
        likers.add(liker);
        if (this.date.after(date)) {
            this.date = date;
        }
    }

    @Nonnull
    public Comment getComment() {
        return comment;
    }

    @Nonnull
    public Date getDate() {
        return date;
    }

    @Nonnull
    public Collection<ApplicationUser> getLikers() {
        return likers;
    }

}
