/*
* Function makes the correction of the auxiliairy verb in the question tag
*
*
*
*/

module.exports = function (ruleManager, sentence, result) {

    if (!ruleManager || !result || !result.tokenIndices || result.tokenIndices.length < 6 || !sentence) {
        debugger;
        console.error("inputs are wrong");
        return false;
    }

    /*
    * to replace the wrong auxiliairy in the question tag
    * we gether all the information on the auxiliairy in the main clause
    * 
    */

    let verb_forms = ruleManager.dictionaries["Verbs Forms"];
    if (!verb_forms) {
        console.error("dictionnary error");
        return false;
    }

    let aux_mainIndex = result.tokenRules[1].tokenIndices[0];
    //console.log("aux Verb of main index = " + aux_mainIndex);
    let aux_mainWord = sentence.tokens[aux_mainIndex].word;
    let aux_mainLemma = sentence.tokens[aux_mainIndex].lemma;
    let aux_mainPOS = sentence.tokens[aux_mainIndex].pos;

    let aux_qtagIndex = result.tokenIndices[result.tokenRules[5].tokenIndices[0]];

    let aux_qtagWord = verb_forms[aux_mainLemma].VBZ;
    if (!aux_qtagWord) {
        console.error("dictionnary error");
        return false;
    }

    if (aux_mainIndex == undefined || aux_qtagIndex == undefined) {
        debugger;
        console.error("problem with auxiliairies");
        return false;
    }


    var correction = {
        "type": "replaceAttValue",
        "suggestionIndice": 0,
        "att": "word",
        "text": aux_qtagWord,
        "tokenIndice": aux_qtagIndex
    };

    ruleManager.AddCorrection(result, 0, correction);

    var correction = {
        "type": "replaceAttValue",
        "suggestionIndice": 0,
        "att": "lemma",
        "text": aux_mainLemma,
        "tokenIndice": aux_qtagIndex
    };

    ruleManager.AddCorrection(result, 0, correction);

    var correction = {
        "type": "replaceAttValue",
        "suggestionIndice": 0,
        "att": "pos",
        "text": "VBZ",
        "tokenIndice": aux_qtagIndex
    };

    ruleManager.AddCorrection(result, 0, correction);
    return true;
    //debugger;
}