/*
* Function correcting compound ordinal numbers:
* "twenty first" --> "twenty-first"
*/

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

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

    if (result.tokenRules.length < 3) {
        return false;
    }

    let number1 = sentence.tokens[result.tokenRules[1].tokenIndices[0]].word;
    // console.log("number1 : " + number1);

    let number1Index = result.tokenRules[1].tokenIndices[0];

    let number2 = sentence.tokens[result.tokenRules[2].tokenIndices[0]].word;
    // console.log("number2 : " + number2);

    let number2Index = result.tokenRules[2].tokenIndices[0];

    let compound_noun = number1.concat("-", number2);
    // console.log("compound_noun corrigé: " + compound_noun);

    var correction = {
        "type": "delete",
        "suggestionIndice": 0,
        "tokenIndice": number2Index
    };

    ruleManager.AddCorrection(result, 0, correction);

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

    ruleManager.AddCorrection(result, 0, correction);

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

    ruleManager.AddCorrection(result, 0, correction);

    //debugger;

    return true;
};