/* eslint-disable class-methods-use-this */
import fetch from 'node-fetch';
import FormData from 'form-data';
import fs from 'fs';

const ALPR_API_PATH = 'https://api.platerecognizer.com/v1/plate-reader/';
const API_KEY = process.env.ALPR_API_KEY;

class PlateRecognizr {
  async handle(image) {
    const response = await this.fetch(image);
    console.log(await response.json());
    return response;
  }

  fetch(image) {
    const body = new FormData();
    body.append('upload', image);
    body.append('regions', 'ee'); // Change to your country
    return fetch(ALPR_API_PATH, {
      method: 'POST',
      headers: {
        Authorization: `Token ${API_KEY}`,
      },
      body,
    });
  }
}

export default PlateRecognizr;
