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

import com.atlassian.soy.renderer.JsExpression;
import com.atlassian.stash.internal.web.soy.functions.SoyArgumentUtils;
import com.atlassian.bitbucket.nav.NavBuilder;

/**
 * A Soy function which can be used both client- and server-side to get a hook avatar.
 */
public class HookAvatarUrlFunction extends BaseNavFunction {

    public HookAvatarUrlFunction(NavBuilder navBuilder) {
        super(navBuilder, "hookAvatarUrl", 2);
    }

    @Override
    protected NavBuilder.Builder initBuilder(Object... args) {
        String key = SoyArgumentUtils.getStringArgument(args, 0);
        String version = SoyArgumentUtils.getStringArgument(args, 1);
        return navBuilder.rest().hooks().hook(key).avatar(version);
    }

    @Override
    protected JsNavBuilder initJsBuilder(JsExpression... args) {
        return new JsNavBuilder()
                .callMethod("rest")
                .callMethod("hooks")
                .callMethod("hook", args[0])
                .callMethod("avatar", args[1]);
    }
}
