import { NominatimClient } from "./nominatim";
class GeocodeController {
  constructor() {
    this.defaultClient = "nominatim";
  }
  /**
   * Performs forward geocoding by converting an address to a geolocation.
   * @param options Forward geocoding options object.
   * @param clientOptions Additional client options object.
   */
  async forward(options, clientOptions) {
    let client = this.getClient(options.client);
    let res = await client.forward(options, clientOptions);
    this.glForwardGeocode.emit({
      options: options,
      response: res,
    });
    return res;
  }
  /**
   * Performs reverse geocoding by converting a geolocation to an address.
   * @param options Reverse geocoding options object.
   * @param clientOptions Additional client options.
   */
  async reverse(options, clientOptions) {
    let client = this.getClient(options.client);
    let res = await client.reverse(options, clientOptions);
    this.glReverseGeocode.emit({
      options: options,
      response: res,
    });
    return res;
  }
  getClient(id) {
    return GeocodeController.clients[id || this.defaultClient];
  }
  /**
   * Adds a client to the geocode controller
   * @param id The ide of the client
   * @param service A client able to handle nominatim results. For an example see {@link ./nominatim}
   */
  static async addClient(id, service) {
    GeocodeController.clients[id] = service;
  }
  static get is() { return "gl-geocode-controller"; }
  static get properties() {
    return {
      "defaultClient": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Default client used to perform the geocoding. It can be overridden in\nthe options provided to `forward()` and `reverse()`."
        },
        "attribute": "default-client",
        "reflect": false,
        "defaultValue": "\"nominatim\""
      }
    };
  }
  static get events() {
    return [{
        "method": "glForwardGeocode",
        "name": "glForwardGeocode",
        "bubbles": true,
        "cancelable": true,
        "composed": true,
        "docs": {
          "tags": [],
          "text": "Emitted when a forward geocode request completes."
        },
        "complexType": {
          "original": "any",
          "resolved": "any",
          "references": {}
        }
      }, {
        "method": "glReverseGeocode",
        "name": "glReverseGeocode",
        "bubbles": true,
        "cancelable": true,
        "composed": true,
        "docs": {
          "tags": [],
          "text": "Emitted when a reverse geocode request completes."
        },
        "complexType": {
          "original": "any",
          "resolved": "any",
          "references": {}
        }
      }];
  }
  static get methods() {
    return {
      "forward": {
        "complexType": {
          "signature": "(options: ForwardGeocodeOptions, clientOptions?: geocodeClientOptions) => Promise<GeocodeResponse[]>",
          "parameters": [{
              "tags": [{
                  "name": "param",
                  "text": "options Forward geocoding options object."
                }],
              "text": "Forward geocoding options object."
            }, {
              "tags": [{
                  "name": "param",
                  "text": "clientOptions Additional client options object."
                }],
              "text": "Additional client options object."
            }],
          "references": {
            "Promise": {
              "location": "global",
              "id": "global::Promise"
            },
            "GeocodeResponse": {
              "location": "import",
              "path": "./geocode-interface",
              "id": "src/components/geocode-controller/geocode-interface.ts::GeocodeResponse"
            },
            "ForwardGeocodeOptions": {
              "location": "import",
              "path": "./geocode-interface",
              "id": "src/components/geocode-controller/geocode-interface.ts::ForwardGeocodeOptions"
            },
            "geocodeClientOptions": {
              "location": "import",
              "path": "./geocode-interface",
              "id": "src/components/geocode-controller/geocode-interface.ts::geocodeClientOptions"
            }
          },
          "return": "Promise<GeocodeResponse[]>"
        },
        "docs": {
          "text": "Performs forward geocoding by converting an address to a geolocation.",
          "tags": [{
              "name": "param",
              "text": "options Forward geocoding options object."
            }, {
              "name": "param",
              "text": "clientOptions Additional client options object."
            }]
        }
      },
      "reverse": {
        "complexType": {
          "signature": "(options: ReverseGeocodeOptions, clientOptions?: geocodeClientOptions) => Promise<any>",
          "parameters": [{
              "tags": [{
                  "name": "param",
                  "text": "options Reverse geocoding options object."
                }],
              "text": "Reverse geocoding options object."
            }, {
              "tags": [{
                  "name": "param",
                  "text": "clientOptions Additional client options."
                }],
              "text": "Additional client options."
            }],
          "references": {
            "Promise": {
              "location": "global",
              "id": "global::Promise"
            },
            "ReverseGeocodeOptions": {
              "location": "import",
              "path": "./geocode-interface",
              "id": "src/components/geocode-controller/geocode-interface.ts::ReverseGeocodeOptions"
            },
            "geocodeClientOptions": {
              "location": "import",
              "path": "./geocode-interface",
              "id": "src/components/geocode-controller/geocode-interface.ts::geocodeClientOptions"
            }
          },
          "return": "Promise<any>"
        },
        "docs": {
          "text": "Performs reverse geocoding by converting a geolocation to an address.",
          "tags": [{
              "name": "param",
              "text": "options Reverse geocoding options object."
            }, {
              "name": "param",
              "text": "clientOptions Additional client options."
            }]
        }
      },
      "addClient": {
        "complexType": {
          "signature": "(id: string, service: geocodeClient) => Promise<void>",
          "parameters": [{
              "tags": [{
                  "name": "param",
                  "text": "id The ide of the client"
                }],
              "text": "The ide of the client"
            }, {
              "tags": [{
                  "name": "param",
                  "text": "service A client able to handle nominatim results. For an example see {@link ./nominatim}"
                }],
              "text": "A client able to handle nominatim results. For an example see {@link ./nominatim}"
            }],
          "references": {
            "Promise": {
              "location": "global",
              "id": "global::Promise"
            },
            "geocodeClient": {
              "location": "import",
              "path": "./geocode-interface",
              "id": "src/components/geocode-controller/geocode-interface.ts::geocodeClient"
            }
          },
          "return": "Promise<void>"
        },
        "docs": {
          "text": "Adds a client to the geocode controller",
          "tags": [{
              "name": "param",
              "text": "id The ide of the client"
            }, {
              "name": "param",
              "text": "service A client able to handle nominatim results. For an example see {@link ./nominatim}"
            }]
        }
      }
    };
  }
  static get stencilHasStaticMembersWithInit() { return true; }
}
GeocodeController.clients = {};
export { GeocodeController };
GeocodeController.addClient("nominatim", new NominatimClient());
//# sourceMappingURL=geocode-controller.js.map
