class NominatimQuery {
  limit;
  countrycodes;
  format;
  addressdetails;
  postalcode;
  q;

  toString() {
    const obj = this;
    const query =
      "?" +
      Object.keys(obj)
        .reduce(function (a, k) {
          a.push(k + "=" + encodeURIComponent(obj[k] ?? ""));
          return a;
        }, [])
        .join("&");
    return query;
  }

  constructor(init) {
    if (init !== undefined) {
      Object.assign(this, init);
    } else {
      this.limit = 10;
      this.countrycodes = "PL";
      this.format = "json";
      this.addressdetails = true;
    }
  }
}

export default NominatimQuery;
