/*
* 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 MD_form = ruleManager.dictionaries.modal_verb_form_before_not;
    if (!MD_form) {
        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 = sentence.tokens[aux_qtagIndex].word;
    // let aux_qtagLemma = sentence.tokens[aux_qtagIndex].lemma;
    // let aux_qtagPOS = sentence.tokens[aux_qtagIndex].pos;

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

    /*
    * Check the conjugation of the aux_main
    *
    */


    // let not_exist_in_main = false;
    // if (result.tokenRules[2].tokenIndices.length == 1) {
    //     not_exist_in_main = true;
    // }

    


    // let not_exist_in_qtag = false;
    // if (result.tokenRules[8].tokenIndices.length == 1) {
    //     not_exist_in_qtag = true;
    // }


    // if (aux_mainLemma != aux_qtagLemma){

    // }

    // if (not_exist_in_qtag){
    //     for (var key in MD_form) {
    //         if (aux_mainWord === key) {
    //             aux_mainWord = ruleManager.dictionaries.modal_verb_form_before_not[key].short;
    //             break;
    //         }

    //     }
    // }




    var correction = {
        "type": "replaceAttValue",
        "suggestionIndice": 0,
        "att": "word",
        "text": aux_mainLemma,
        "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": "VBP",
        "tokenIndice": aux_qtagIndex
    };

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