import {
  alprFetchSuccess, alprFetchStart, dataFetchStart, dataFetchSuccess,
} from '@slice/RecognitionSlice';

const API_BASE_PATH = process.env.API_BASE_PATH;
console.log(process.env.API_BASE_PATH);
export const getPlateRecognized = (image) => async (dispatch) => {
  console.log(image);
  dispatch(alprFetchStart());
  const body = new FormData();
  body.append('upload', image);
  try {
    console.log(API_BASE_PATH);
    const response = await fetch(`${API_BASE_PATH}/alpr`, {
      method: 'POST',
      body,
    });
    console.log(response);
    const data = await response.json();
    dispatch(alprFetchSuccess(data));
    console.log(data);
  } catch (e) {
    console.log(e);
  }
};

export const fetchDataForPlate = (plate) => async (dispatch) => {
  dispatch(dataFetchStart());
  console.log('Fetching data for plate', plate);
  try {
    const response = await fetch(`${API_BASE_PATH}/${plate}`, {
      method: 'GET',
    });
    console.log(response);
    const data = await response.json();
    dispatch(dataFetchSuccess(data));
    console.log(data);
  } catch (e) {
    console.log(e);
  }
};

export const getPlateData = (plate) => null;
