package com.atlassian.stash.internal.repository.sync.rest;

import com.atlassian.bitbucket.repository.RefType;
import com.atlassian.bitbucket.repository.sync.RejectedRef;
import com.atlassian.bitbucket.repository.sync.RejectedRefState;
import com.atlassian.bitbucket.rest.annotation.JsonSurrogate;
import com.atlassian.bitbucket.rest.repository.RestMinimalRef;
import com.google.common.base.Function;
import org.codehaus.jackson.map.annotate.JsonSerialize;

import static com.atlassian.bitbucket.repository.StandardRefType.BRANCH;

/**
 * @since 2.6
 */
@JsonSerialize
@JsonSurrogate(RejectedRef.class)
public class RestRejectedRef extends RestMinimalRef {

    public static final Function<RejectedRef, RestRejectedRef> REST_TRANSFORM =
            new Function<RejectedRef, RestRejectedRef>() {

                @Override
                public RestRejectedRef apply(RejectedRef ref) {
                    return new RestRejectedRef(ref);
                }
            };

    private static final String STATE = "state";
    private static final String TAG = "tag";

    public RestRejectedRef(RejectedRef ref) {
        this(ref.getId(), ref.getDisplayId(), ref.getType(), ref.getState(), ref.isTag());
    }

    private RestRejectedRef(String id, String displayId, RefType refType, RejectedRefState state, boolean tag) {
        super(id, displayId, refType);

        put(STATE, state);
        put(TAG, tag);
    }

    // REST Documentation Examples
    public static final RestRejectedRef AHEAD_EXAMPLE = new RestRejectedRef("refs/heads/master",
            "master", BRANCH, RejectedRefState.AHEAD, false);
    public static final RestRejectedRef DIVERGED_EXAMPLE = new RestRejectedRef("refs/heads/master",
            "master", BRANCH, RejectedRefState.DIVERGED, false);
}
