import AppActionTypes from "./app.types";

const INITIAL_STATE = {
  cameraJobId: null,
  cameraJob: null,
  documentUploadInProgress: null,
  documentUploadError: null,
  deleteAfterUpload: false,
  theme: "system",
};

const appReducer = (state = INITIAL_STATE, action) => {
  switch (action.type) {
    case AppActionTypes.SET_CAMERA_JOB_ID:
      return {
        ...state,
        cameraJobId: action.payload,
      };
    case AppActionTypes.SET_CAMERA_JOB:
      return {
        ...state,
        cameraJob: action.payload,
      };
    case AppActionTypes.DOCUMENT_UPLOAD_START:
      return {
        ...state,
        documentUploadError: null,
        documentUploadInProgress: action.payload,
      };
    case AppActionTypes.DOCUMENT_UPLOAD_SUCCESS:
      return {
        ...state,
        documentUploadError: null,
        documentUploadInProgress: null,
      };
    case AppActionTypes.DOCUMENT_UPLOAD_FAILURE:
      return {
        ...state,
        documentUploadError: action.payload,
        documentUploadInProgress: null,
      };
    case AppActionTypes.TOGGLE_DLETE_AFTER_UPLOAD:
      return {
        ...state,
        deleteAfterUpload: !state.deleteAfterUpload,
      };
    case AppActionTypes.SET_THEME:
      return { ...state, theme: action.payload };
    default:
      return state;
  }
};

export default appReducer;
