package com.atlassian.bitbucket.rest.content;

import com.atlassian.bitbucket.content.ContentTreeNode;
import com.atlassian.bitbucket.content.Submodule;
import com.atlassian.bitbucket.rest.annotation.JsonSurrogate;
import com.atlassian.bitbucket.rest.RestMapEntity;
import org.codehaus.jackson.map.annotate.JsonSerialize;

@JsonSerialize
@JsonSurrogate(Submodule.class)
public class RestSubmodule extends RestMapEntity implements RestContentTreeNode {

    public RestSubmodule(Submodule submodule) {
        this(RestPath.fromPath(submodule.getPath()), submodule.getContentId(), submodule.getUrl(),
                submodule.getRepositoryUrl(), submodule.getBrowseUrl());
    }

    // Required for REST documentation
    private RestSubmodule(RestPath path, String contentId, String url, String repositoryUrl, String browseUrl) {
        put("path", path);
        put("contentId", contentId);
        put("type", ContentTreeNode.Type.SUBMODULE);
        put("url", url);
        putIfNotNull("repositoryUrl", repositoryUrl);
        putIfNotNull("browseUrl", browseUrl);
    }

    // REST Documentation Examples

    public static final RestSubmodule EXAMPLE = new RestSubmodule(RestPath.EXAMPLE, "0a943a29376f2336b78312d99e65da17048951db",
            "ssh://git@localhost:7999/STASH/stash.git", "http://localhost:7990/bitbucket/projects/PROJECT_1/repos/rep_1/browse",
            "http://localhost:7990/bitbucket/projects/PROJECT_1/repos/rep_1/browse?at=996b4f5a7e242a29fe573582d98f5174142bb97c");
}
