package com.atlassian.bitbucket.internal.importer.event;

import com.atlassian.analytics.api.annotations.EventName;
import com.atlassian.bitbucket.event.ApplicationEvent;
import com.atlassian.bitbucket.internal.importer.SourceType;
import com.atlassian.bitbucket.internal.importer.repository.ImportJob;
import com.atlassian.bitbucket.internal.importer.repository.RepositoryImportTask;
import com.atlassian.event.api.AsynchronousPreferred;

import javax.annotation.Nonnull;

import static java.util.Objects.requireNonNull;

/**
 * This event keeps track of {@link ImportJob}s being created. It contains the jobId so that it can be linked with each
 * repository task import event ({@link RepositoryImportTaskStateChangedEvent}) and contains the number of
 * {@link RepositoryImportTask}s that are associated with this event. At this stage, we have already dropped the
 * {@link SourceType} so we are unable to know the external source for this {@link ImportJob}.
 */
@AsynchronousPreferred
@EventName("stash.importer.job.created")
public class ImportJobCreatedEvent extends ApplicationEvent {
    private final long jobId;
    private final int projectId;
    private final int totalRepositoryImportTasks;

    public ImportJobCreatedEvent(@Nonnull Object source, long jobId, int projectId, int totalRepositoryImportTasks) {
        super(requireNonNull(source));
        this.jobId = jobId;
        this.projectId = projectId;
        this.totalRepositoryImportTasks = totalRepositoryImportTasks;
    }

    public long getJobId() {
        return jobId;
    }

    public int getProjectId() {
        return projectId;
    }

    public int getTotalRepositoryImportTasks() {
        return totalRepositoryImportTasks;
    }
}
