{"size": 852, "ext": "js", "max_stars_repo_path": "themes/sdlt/src/js/utils/TaskParser.js", "max_stars_repo_name": "rlukman/SDLT", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "themes/sdlt/src/js/utils/TaskParser.js", "max_issues_repo_name": "rlukman/SDLT", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "themes/sdlt/src/js/utils/TaskParser.js", "max_forks_repo_name": "rlukman/SDLT", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.3428571429, "max_line_length": 74, "alphanum_fraction": 0.6185446009}
// @flow

import toString from "lodash/toString";
import get from "lodash/get";
import type {Task} from "../types/Task";
import QuestionParser from "./QuestionParser";

export default class TaskParser {

  static parseFromJSONObject(jsonObject: *): Task {
    const id = toString(get(jsonObject, "ID", ""));
    const name = toString(get(jsonObject, "Name", ""));

    let type = toString(get(jsonObject, "TaskType", ""));
    switch (type) {
      case "questionnaire":
      case "selection":
        break;
      default:
        type = "questionnaire";
    }

    let questions = [];
    const schemaJSON = toString(get(jsonObject, "QuestionsDataJSON", ""));
    if (schemaJSON) {
      questions = QuestionParser.parseQuestionsFromJSON({
        schemaJSON,
        answersJSON: "{}"
      });
    }

    return {id, name, type, questions};
  }
}
