import {
  START_TUTORIAL,
  SKIP_TUTORIAL,
  RESET_TUTORIAL,
  COMPLETE_TUTORIAL,
  LOAD_TUTORIALS
} from 'actions/tutorials';
import Immutable from 'immutable';

const Tutorial = new Immutable.Record({
  completed: null
});

export default function tutorialReducer(tutorials = new Immutable.Map(), action) {
  switch (action.type) {
  case START_TUTORIAL:
    return tutorials.set(action.subject, new Tutorial({completed: false}));
  case SKIP_TUTORIAL:
    return tutorials.set(action.subject, new Tutorial({completed: true}));
  case RESET_TUTORIAL:
    return tutorials.get(action.subject).set('completed', false);
  case COMPLETE_TUTORIAL:
    return tutorials.setIn([action.subject, 'completed'], true);
  case LOAD_TUTORIALS:
    return Immutable.fromJS(action.tutorials);
  default:
    return tutorials;
  }
}
