import m from "mithril"

export const Questionnaire = {
    list: [],
    current: {},
    sections: [],
    reports: [],
    message: "",
    error: "",
    fetchList: function() {
        m.request({
            method: "GET",
            url: "/questionnaires"
        })
        .then(function(res) {
            Questionnaire.list = res.data
        })
    },
    fetchCurrent: function() {
        m.request({
            method: "GET",
            url: "/questionnaires/:id",
            data: Questionnaire.current
        })
        .then(function(res) {
            Questionnaire.current = res.data
        })
    },
    fetchSections: function() {
        m.request({
            method: "GET",
            url: "/questionnaires/:id/sections",
            data: Questionnaire.current
        })
        .then(function(res) {
            Questionnaire.sections = res.data
        })
    },
    fetchReports: function() {
        m.request({
            method: "GET",
            url: "/questionnaires/:id/reports",
            data: Questionnaire.current
        })
        .then(function(res) {
            Questionnaire.reports = res.data
        })
    },
    upload: function() {
        m.request({
            method: "POST",
            url: "/questionnaires",
            data: Questionnaire.current
        })
        .then(function(res) {
            Questionnaire.current = res.data
        })
    },
    uploadSection: function() {
        
    }
    update: function() {
        m.request({
            method: "PUT",
            url: "/questionnaires/:id",
            data: Questionnaire.current
        })
    },
    remove: function() {
        m.request({
            method: "DELETE",
            url: "/questionnaires/:id",
            data: Questionnaire.current
        })
    }
}
