package com.atlassian.stash.internal.notification.pull.activity;

import com.google.common.collect.ImmutableMap;

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

/**
 * An abstract BatchEmailActivity that implements a common base method for getting
 * the BatchActivity data.
 */
abstract class AbstractBatchEmailActivity implements BatchEmailActivity {

    private static final String DATE_KEY = "date";
    private static final String TYPE_KEY = "type";

    protected AbstractBatchEmailActivity() {
    }

    @Nonnull
    @Override
    public Map<String, Object> asData() {
        ImmutableMap.Builder<String, Object> builder = dataBuilder();
        populateData(builder);
        return builder.build();
    }

    abstract void populateData(ImmutableMap.Builder<String, Object> builder);

    private ImmutableMap.Builder<String, Object> dataBuilder() {
        return ImmutableMap.<String, Object>builder()
            .put(DATE_KEY, getDate())
            .put(TYPE_KEY, getType());
    }
}