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

const proc = PROCEDURES.get_languages

export type ReferenceLanguage = {
  id: number,
  iso_639_1: string,
  lexic: number,
  name_en: string,
  name_national: string | null,
  name_ru: string,
  short_name: string,
  ts: number,
}

export type ReferenceLanguages = Array<ReferenceLanguage>

export const getLanguages = async (): Promise<ReferenceLanguages> => {
  const config = {
    body: {
      params: {},
      proc,
    },
  }

  const response = await callApi({
    config,
    url: DATA_URL,
  })

  return response
}
