//
// SEARCHAPI.swift
//
// Generated by openapi-generator
// https://openapi-generator.tech
//

import Foundation
import Alamofire



open class SEARCHAPI {
    /**
     Forward Geocoding
     
     - parameter q: (query) Address to geocode 
     - parameter viewbox: (query) The preferred area to find search results.  To restrict results to those within the viewbox, use along with the bounded option. Tuple of 4 floats. Any two corner points of the box - &#x60;max_lon,max_lat,min_lon,min_lat&#x60; or &#x60;min_lon,min_lat,max_lon,max_lat&#x60; - are accepted in any order as long as they span a real box.  (optional)
     - parameter limit: (query) Limit the number of returned results. Default is 10. (optional, default to 10)
     - parameter acceptLanguage: (query) Preferred language order for showing search results, overrides the value specified in the Accept-Language HTTP header. Defaults to en. To use native language for the response when available, use accept-language&#x3D;native (optional)
     - parameter countrycodes: (query) Limit search to a list of countries. (optional)
     - parameter completion: completion handler to receive the data and the error objects
     */
    open class func search(q: String, viewbox: String? = nil, limit: Int64? = nil, acceptLanguage: String? = nil, countrycodes: String? = nil, completion: @escaping ((_ data: Any?,_ error: Error?) -> Void)) {
        searchWithRequestBuilder(q: q, viewbox: viewbox, limit: limit, acceptLanguage: acceptLanguage, countrycodes: countrycodes).execute { (response, error) -> Void in
            completion(response?.body, error)
        }
    }


    /**
     Forward Geocoding
     - GET /search.php
     - The Search API allows converting addresses, such as a street address, into geographic coordinates (latitude and longitude). These coordinates can serve various use-cases, from placing markers on a map to helping algorithms determine nearby bus stops. This process is also known as Forward Geocoding.
     - API Key:
       - type: apiKey token (QUERY)
       - name: token
     - parameter q: (query) Address to geocode 
     - parameter viewbox: (query) The preferred area to find search results.  To restrict results to those within the viewbox, use along with the bounded option. Tuple of 4 floats. Any two corner points of the box - &#x60;max_lon,max_lat,min_lon,min_lat&#x60; or &#x60;min_lon,min_lat,max_lon,max_lat&#x60; - are accepted in any order as long as they span a real box.  (optional)
     - parameter limit: (query) Limit the number of returned results. Default is 10. (optional, default to 10)
     - parameter acceptLanguage: (query) Preferred language order for showing search results, overrides the value specified in the Accept-Language HTTP header. Defaults to en. To use native language for the response when available, use accept-language&#x3D;native (optional)
     - parameter countrycodes: (query) Limit search to a list of countries. (optional)
     - returns: RequestBuilder<Any> 
     */
    open class func searchWithRequestBuilder(q: String, viewbox: String? = nil, limit: Int64? = nil, acceptLanguage: String? = nil, countrycodes: String? = nil) -> RequestBuilder<Any> {
        let path = "/search.php"
        let URLString = unwiredAPI.basePath + path
        let parameters: [String:Any]? = nil
        
        var url = URLComponents(string: URLString)
        url?.queryItems = APIHelper.mapValuesToQueryItems([
            "q": q, 
            "viewbox": viewbox, 
            "limit": limit?.encodeToJSON(), 
            "accept-language": acceptLanguage, 
            "countrycodes": countrycodes
        ])

        let requestBuilder: RequestBuilder<Any>.Type = unwiredAPI.requestBuilderFactory.getBuilder()

        return requestBuilder.init(method: "GET", URLString: (url?.string ?? URLString), parameters: parameters, isBody: false)
    }

}
