let extractUrl = 'http://localhost:5001/infill-development/us-central1/extractColumns'
let importUrl = 'http://localhost:5001/infill-development/us-central1/importSheet'

export const extractColumns = async (data) => {
  let formData = new FormData()
  formData.append('data', data)

  let response = await fetch(extractUrl, {
    method: 'POST',
    body: formData,
  })

  let json = await response.json()

  if (json.error) {
    throw new Error(json.error)
  }

  return json
}

export const importSheet = async (file, schema) => {
  let formData = new FormData()
  formData.append('schema', JSON.stringify(schema))
  formData.append('data', file)
  formData.append('type', 'CUSTOM')

  console.log('IMPORT SCHEMA: ', schema)

  let response = await fetch(importUrl, {
    method: 'POST',
    body: formData,
  })

  let json = await response.json()

  return json.importId
}
