import {merge} from 'lodash'
import { CHANGE_QUESTION, CHANGE_RESPONSE, REMOVE_OPTION, ADD_OPTION } from '../actions'

const initialState = {
  "description": "Lorem ipsum",
  "id": "question-1",
  "number": "1",
  "title": "Which side of the force are you on?",
  "type": "General",
  "guidance": {
    "title": "Include",
    "text": "Maecenas faucibus mollis interdum."
  },
  "answers": [{
        "id": "permanent-or-family-home-answer",
        "description": "",
        "mandatory": true,
        "guidance": "<p>For most people, their permanent home will be the address where they spend the most time.</p>",
        "options": [{
            "label": "Yes",
            "value": "Yes"
        }, {
            "label": "No",
            "value": "No",
            "description": "For example this is a second address or holiday home"
        }],
        "type": "Radio",
        "validation": {
            "messages": {
                "MANDATORY": "Please select an answer to continue"
            }
        }
    }],
}

const question = (state = initialState, action) => {
  switch (action.type) {
    case CHANGE_QUESTION:
      return {...merge(state, action.value)}
    case CHANGE_RESPONSE:
      const index = action.index
      return Object.assign({}, state, {
        answers: [
          ...state.answers.slice(0, index),
          Object.assign({}, state.answers[index], action.value),
          ...state.answers.slice(index + 1)
        ]
      })
    case REMOVE_OPTION:
      let newState = {...state}
      newState.answers[action.answerIndex].options.splice(action.optionIndex, 1)
      return newState
    case ADD_OPTION:
      newState = {...state}
      newState.answers[action.answerIndex].options.push(action.option)
      return newState
    default:
      return state
  }
}

export default question

@@ -1210,167 +1210,50 @@
     
-const index = action.index%0A      return Object.assign(%7B%7D, state, %7B%0A        answers: %5B%0A          ...state.answers.slice(0, index),%0A          Object.assign(%7B%7D, s
+let newState = %7B...state%7D%0A      merge(newS
 tate
@@ -1261,16 +1261,23 @@
 answers%5B
+action.
 index%5D, 
@@ -1293,72 +1293,30 @@
 lue)
-,
 %0A      
-    ...state.answers.slice(index + 1)%0A        %5D%0A      %7D)
+return newState
 %0A   
@@ -1336,26 +1336,22 @@
 OPTION:%0A
+
       
-let 
 newState

Replace Object.assign with destructing.