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

import com.atlassian.soy.renderer.JsExpression;

public class JsNavBuilder {

    private final StringBuilder sb = new StringBuilder();

    public JsNavBuilder() {
        sb.append("require('bitbucket/util/navbuilder')");
    }

    public JsExpression build() {
        callMethod("build");
        return new JsExpression(sb.toString());
    }

    public JsNavBuilder callMethod(String methodName, JsExpression... args) {
        sb.append(".").append(methodName).append("(");
        String sep = "";
        for (JsExpression arg : args) {
            sb.append(sep);
            sb.append(arg.getText());
            sep = ", ";
        }
        sb.append(")");
        return this;
    }

    public JsNavBuilder admin() {
        return callMethod("admin");
    }

    public JsNavBuilder withParams(JsExpression expr) {
        return callMethod("withParams", expr);
    }

    public JsNavBuilder withParamsIfAvailable(JsExpression[] exprs, int i) {
        if (exprs.length > i) {
            withParams(exprs[i]);
        }
        return this;
    }

    public JsNavBuilder withFragment(JsExpression expr) {
        return callMethod("withFragment", expr);
    }

    public JsNavBuilder withFragmentIfAvailable(JsExpression[] exprs, int i) {
        if (exprs.length > i) {
            withFragment(exprs[i]);
        }
        return this;
    }

    public JsNavBuilder captcha() {
        return callMethod("captcha");
    }

    public JsNavBuilder createRepo() {
        return callMethod("createRepo");
    }

    public JsNavBuilder allProjects() {
        return callMethod("allProjects");
    }

    public JsNavBuilder project(JsExpression arg) {
        return callMethod("project", arg);
    }

    public JsNavBuilder repo(JsExpression arg) {
        return callMethod("repo", arg);
    }

    public JsNavBuilder branches() {
        return callMethod("branches");
    }

    public JsNavBuilder commits() {
        return callMethod("commits");
    }

    public JsNavBuilder compare() {
        return callMethod("compare");
    }

    public JsNavBuilder tags() {
        return callMethod("tags");
    }

    public JsNavBuilder login() {
        return callMethod("login");
    }

    public JsNavBuilder logout() {
        return callMethod("logout");
    }

    public JsNavBuilder browse() {
        return callMethod("browse");
    }

    public JsNavBuilder at(JsExpression arg) {
        return callMethod("at", arg);
    }

    public JsNavBuilder path(JsExpression arg) {
        return callMethod("path", arg);
    }

    public JsNavBuilder commit(JsExpression arg) {
        return callMethod("commit", arg);
    }

    public JsNavBuilder users() {
        return callMethod("users");
    }

    public JsNavBuilder user(JsExpression arg) {
        return callMethod("user", arg);
    }

    public JsNavBuilder groups() {
        return callMethod("groups");
    }

    public JsNavBuilder view(JsExpression arg) {
        return callMethod("view", arg);
    }

    public JsNavBuilder createPullRequest() {
        return callMethod("createPullRequest");
    }

    public JsNavBuilder pullRequest(JsExpression arg) {
        return callMethod("pullRequest", arg);
    }

    public JsNavBuilder unwatch() {
        return callMethod("unwatch");
    }

    public JsNavBuilder overview() {
        return callMethod("overview");
    }

    public JsNavBuilder diff() {
        return callMethod("diff");
    }

    public JsNavBuilder pullRequests() {
        return callMethod("pullRequests");
    }

    public JsNavBuilder comment(JsExpression arg) {
        return callMethod("comment", arg);
    }

    public JsNavBuilder activity(JsExpression arg) {
        return callMethod("activity", arg);
    }

    public JsNavBuilder avatar(JsExpression arg) {
        return callMethod("avatar", arg);
    }

    public JsNavBuilder fork() {
        return callMethod("fork");
    }

    public JsNavBuilder settings() {
        return callMethod("settings");
    }
}
