package com.atlassian.bitbucket.internal.branch.automerge.rest;

import com.atlassian.bitbucket.internal.branch.automerge.AutoMerge;
import com.atlassian.bitbucket.rest.RestMapEntity;
import com.atlassian.bitbucket.rest.annotation.JsonSurrogate;
import com.atlassian.bitbucket.rest.repository.RestBranch;
import org.codehaus.jackson.map.annotate.JsonSerialize;

import javax.annotation.Nonnull;

import static com.google.common.base.Preconditions.checkNotNull;

@JsonSerialize
@JsonSurrogate(AutoMerge.class)
public class RestAutoMerge extends RestMapEntity {

    public static final String STATUS = "status";
    public static final String PATH = "path";

    @SuppressWarnings("unused") //Required for Jersey
    public RestAutoMerge() {
    }

    public RestAutoMerge(@Nonnull AutoMerge autoMerge) {
        checkNotNull(autoMerge, "autoMerge");
        put(STATUS, new RestAutoMergeStatus(autoMerge.getStatus()));
        put(PATH, transform(autoMerge.getPath(), RestBranch.REST_TRANSFORM));
    }
}
