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

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

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

    public static final String CLONE_URL = "cloneUrl";
    public static final String CREATED = "created";
    public static final String EXTERNAL_REPO_NAME = "externalRepoName";
    public static final String FAILURE_TYPE = "failureType";
    public static final String IMPORT_TASK_STATE = "state";
    public static final String LAST_UPDATED = "lastUpdated";
    public static final String REPOSITORY = "repository";
    public static final String TASK_ID = "taskId";

    public RestRepositoryImportTask(RepositoryImportTask task) {
        put(CLONE_URL, task.getCloneUrl());
        put(CREATED, task.getCreated());
        put(EXTERNAL_REPO_NAME, task.getExternalRepoName());
        put(FAILURE_TYPE, task.getFailureType());
        put(IMPORT_TASK_STATE, task.getState());
        put(LAST_UPDATED, task.getLastUpdated());
        put(TASK_ID, task.getTaskId());

        task.getRepository().ifPresent(repository -> put(REPOSITORY, new RestRepository(repository, true)));
    }
}
