package com.atlassian.bitbucket.rest.repository;

import com.atlassian.bitbucket.repository.*;
import com.atlassian.bitbucket.rest.RestMapEntity;
import com.atlassian.bitbucket.rest.annotation.JsonSurrogate;

@JsonSurrogate(RefChange.class)
public class RestRefChange extends RestMapEntity {

    public static String KEY_REF = "ref";
    public static String KEY_REF_ID = "refId";
    public static String KEY_FROM_HASH = "fromHash";
    public static String KEY_TO_HASH = "toHash";
    public static String KEY_TYPE = "type";

    public RestRefChange(RefChange refChange) {
        put(KEY_REF, new RestMinimalRef(refChange.getRef()));
        put(KEY_REF_ID, refChange.getRef().getId());
        put(KEY_FROM_HASH, refChange.getFromHash());
        put(KEY_TO_HASH, refChange.getToHash());
        put(KEY_TYPE, refChange.getType());
    }

    public static final RestRefChange RESPONSE_EXAMPLE = new RestRefChange(new SimpleRefChange.Builder()
            .ref(new SimpleMinimalRef.Builder()
                    .id("refs/heads/master")
                    .displayId("master")
                    .type(StandardRefType.BRANCH).build())
            .fromHash("6053a1eaa1c009dd11092d09a72f3c41af1b59ad")
            .toHash("d6edcbf924697ab811a867421dab60d954ccad99")
            .type(RefChangeType.UPDATE)
            .build());
}
