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

import com.atlassian.bitbucket.repository.Repository;
import com.atlassian.bitbucket.user.ApplicationUser;
import org.apache.commons.lang3.StringUtils;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
 * @since 2.6
 */
public class MergeRefCommandParameters extends AbstractRefCommandParameters {

    private final String message;

    public MergeRefCommandParameters(@Nonnull Repository repository, @Nonnull Repository upstream,
                                     @Nonnull ApplicationUser user, @Nonnull String refId, @Nullable String message) {
        super(repository, upstream, user, refId);

        //If you're curious, this is coded this way because IDEA's ConstantConditions inspection isn't smart
        //enough to detect that the message field can never be null if the "message" parameter is reassigned
        if (StringUtils.isBlank(message)) {
            this.message = "Merging in latest from upstream (" + upstream.getProject().getKey() + "/" +
                    upstream.getSlug() + ":" + refId + ")";
        } else {
            this.message = StringUtils.trim(message);
        }
    }

    @Nonnull
    public String getMessage() {
        return message;
    }
}
