import { DATA_URL, PROCEDURES } from 'config'
import { callApi } from 'helpers'

const proc = PROCEDURES.get_cities

export type City = {
  id: number,
  name: string,
}

export type Cities = Array<City>

export const getCountryCities = (query: string, countryId: number): Promise<Cities> => {
  const config = {
    body: {
      params: {
        _p_country_id: countryId,
        _p_name: query,
      },
      proc,
    },
  }

  return callApi({
    config,
    url: DATA_URL,
  })
}
