/* eslint-disable no-param-reassign */
import { createSlice } from '@reduxjs/toolkit';

export const initialState = {
  isFetchingALPR: false,
  results: [],
};

const recognitionSlice = createSlice({
  name: 'alpr',
  initialState,
  reducers: {
    alprFetchStart(state) {
      state.isFetchingALPR = true;
    },
    alprFetchSuccess(state, { payload }) {
      state.isFetchingALPR = false;
      state.results = payload.results;
    },
    resetResults(state) {
      state.results = [];
    },
  },
});

export const {
  alprFetchStart,
  alprFetchSuccess,
  resetResults,
} = recognitionSlice.actions;

export default recognitionSlice.reducer;
