package org.javafxdata.datasources.io;

/**
 *
 * @author johan
 */
public class RestRequestBuilder {

    private StringBuilder path;
    private String accept;
    private StringBuilder queryString;

    public RestRequestBuilder() {
        this.path = new StringBuilder();
    }

    public RestRequestBuilder(String host) {
        this.path = new StringBuilder(host);
    }

    public RestRequestBuilder queryParam(String key, String val) {
        if (queryString == null) {
            queryString = new StringBuilder(key).append("=").append(val);
        } else {
            queryString.append("&").append(key).append("=").append(val);
        }
        return this;
    }

    public RestRequestBuilder path(String p) {
        this.path.append("/").append(p);
        return this;
    }
    
    public RestRequestBuilder accept (String a) {
      this.accept = a;
      return this;
    }

    public NetworkSource build() {
        String req = path.toString();
        if (queryString != null) {
            req = req + "?" + queryString;
        }
        NetworkSource answer = new NetworkSource(req);
        if (accept != null) {
            answer.setAccept(accept);
        }
        return answer;
    }
}
