package com.atlassian.stash.internal.web.soy.functions.nav;

import com.atlassian.soy.renderer.JsExpression;
import com.atlassian.bitbucket.comment.Comment;
import com.atlassian.bitbucket.nav.NavBuilder;

public class CommitCommentNavFunction extends BaseCommitNavFunction {
    public CommitCommentNavFunction(NavBuilder navBuilder) {
        super(navBuilder, "nav_commit_comment", 4);
    }

    @Override
    protected JsNavBuilder initJsBuilder(JsExpression... jsExpressions) {
        return commit(jsExpressions).comment(jsExpressions[3]);
    }

    @Override
    protected NavBuilder.Builder initBuilder(Object... args) {
        return commit(args).comment(getCommentId(args));
    }

    private long getCommentId(Object[] args) {
        if (args[3] instanceof Comment) {
            return ((Comment) args[3]).getId();
        }
        return ((Number) args[3]).longValue();
    }
}
