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

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

public class AdminUserListNavFunction extends BaseNavFunction {

    public AdminUserListNavFunction(NavBuilder navBuilder) {
        super(navBuilder, "nav_admin_users", ImmutableSet.of(0, 1));
    }

    @Override
    protected JsNavBuilder initJsBuilder(JsExpression... jsExpressions) {
        if (jsExpressions.length == 0) {
            return new JsNavBuilder().admin().users();
        } else {
            return new JsNavBuilder().admin().users().callMethod("filter", jsExpressions[0]);
        }
    }

    @Override
    protected NavBuilder.Builder initBuilder(Object... args) {
        if (args.length == 0) {
            return navBuilder.admin().users();
        } else  {
            return navBuilder.admin().users().filter(SoyArgumentUtils.getStringArgument(args, 0));
        }
    }

}
