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

import com.atlassian.bitbucket.internal.importer.repository.ImportJob;
import com.atlassian.bitbucket.rest.RestMapEntity;
import com.atlassian.bitbucket.rest.annotation.JsonSurrogate;
import org.codehaus.jackson.map.annotate.JsonSerialize;

import java.util.stream.Collectors;

@JsonSerialize
@JsonSurrogate(ImportJob.class)
public class RestImportJob extends RestMapEntity {

    public static final String CREATED_DATE = "createdDate";
    public static final String JOB_ID = "jobId";
    public static final String TASKS = "tasks";

    public RestImportJob(ImportJob importJob) {
        put(CREATED_DATE, importJob.getCreatedDate());
        put(JOB_ID, importJob.getJobId());
        put(TASKS, importJob.getTasks().stream()
                .map(RestRepositoryImportTask::new)
                .collect(Collectors.toList()));
    }
}
