import { createReducer, on } from '@ngrx/store';
import { initialState } from './state';
import {
  selectedRoom,
  selectedMassDetail,
  massTalkDownloadFailure,
  massTalkDownload,
  massTalkDownloadSuccess,
  clearSelectedRoom
} from './actions';

export const reducer = createReducer(
  initialState,
  on(selectedRoom, (state, action) => {
    return {
      ...state,
      selectedRoom: action.roomSeq
    };
  }),

  on(clearSelectedRoom, (state, action) => {
    return {
      ...state,
      selectedRoom: null
    };
  }),

  on(selectedMassDetail, (state, action) => {
    return {
      ...state,
      selectedMassDetail: action.massEventSeq
    };
  }),

  on(massTalkDownload, (state, action) => {
    return {
      ...state,
      massDetailProcessing: true
    };
  }),
  on(massTalkDownloadSuccess, (state, action) => {
    return {
      ...state,
      massDetailProcessing: false
    };
  }),
  on(massTalkDownloadFailure, (state, action) => {
    return {
      ...state,
      massDetailProcessing: false
    };
  })
);
