import ApplicationActionTypes from "./application.types";
const INITIAL_STATE = {
  watcherStatus: "Not Started",
  watchedPaths: [],
  watcherError: null,
  selectedJobId: null,
};

const applicationReducer = (state = INITIAL_STATE, action) => {
  switch (action.type) {
    case ApplicationActionTypes.SET_WATCHED_PATHS:
      return {
        ...state,
        watchedPaths: action.payload,
      };
    case ApplicationActionTypes.ADD_WATCHED_PATH:
      return {
        ...state,
        watchedPaths: [...state.watchedPaths, action.payload],
      };
    case ApplicationActionTypes.REMOVE_WATCHED_PATH:
      return {
        ...state,
        watchedPaths: state.watchedPaths.filter((p) => p !== action.payload),
      };
    case ApplicationActionTypes.SET_WATCHER_STATUS:
      return {
        ...state,
        watcherStatus: action.payload,
      };
    case ApplicationActionTypes.SET_WATCHER_ERROR:
      return {
        ...state,
        watcherError: action.payload,
      };
    case ApplicationActionTypes.SET_SELECTED_JOB_ID:
      return { ...state, selectedJobId: action.payload };
    default:
      return state;
  }
};

export default applicationReducer;
