package org.jabref.model.database.event;

import java.util.List;

import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.event.EntriesEvent;
import org.jabref.model.entry.event.EntriesEventSource;

import org.jspecify.annotations.Nullable;

/// {@link EntriesAddedEvent} is fired when at least {@link BibEntry} is being added to the {@link org.jabref.model.database.BibDatabase}.
public class EntriesAddedEvent extends EntriesEvent {

    // firstEntry used by listeners that used to listen to AllInsertsFinishedEvent
    // final?
    private final BibEntry firstEntry;

    /// @param bibEntries `List` of `BibEntry` objects which are being added.
    /// @param location   Location affected by this event
    public EntriesAddedEvent(List<BibEntry> bibEntries, EntriesEventSource location) {
        super(bibEntries, location);
        if (bibEntries.isEmpty()) {
            this.firstEntry = null;
        } else {
            this.firstEntry = bibEntries.getFirst();
        }
    }

    public @Nullable BibEntry getFirstEntry() {
        return this.firstEntry;
    }
}
