
package org.jboss.hal.core.finder;

import com.gwtplatform.mvp.shared.proxy.PlaceRequest;

/** Holds state as the user navigates using the finder. */
public class FinderContext {

    public static final String PATH_PARAM = "path";

    private String token;
    private FinderPath path;

    FinderContext() {
        token = null;
        path = new FinderPath();
    }

    void reset(final String token) {
        this.token = token;
        path.clear();
    }

    public void reset(final FinderPath path) {
        this.path = path;
    }

    public String getToken() {
        return token;
    }

    public void setToken(final String token) {
        this.token = token;
    }

    public FinderPath getPath() {
        return path;
    }

    public PlaceRequest toPlaceRequest() {
        PlaceRequest.Builder builder = new PlaceRequest.Builder().nameToken(token);
        if (!path.isEmpty()) {
            builder.with(PATH_PARAM, path.toString());
        }
        return builder.build();
    }
}
