"use strict";
const Overload = require('./overload');

var RuleConditionId = 1;

class TokenRuleCondition {
    constructor(json) {
        if (!json)
        {
            debugger;
        }
        if (json.overloads) {
            this.overloads = Overload.ConvertOverloads(json.overloads);
        }
        if (json.corrections) {
            this.modifications = json.corrections;
        }
        if (json.modifications) {
            this.modifications = json.modifications;
        }
        this.id = RuleConditionId;
        RuleConditionId++;
    }
    ContainsMandatoryEqualCondition(att, values)
    {
        return null;
    }
    _addOverloads(overloads, localOverloads) {
        if (!overloads) {
            debugger;
            return;
        }
        if (!localOverloads) {
            debugger;
            return;
        }
        for (var i=0; i<localOverloads.length; i++)
        {
            if (overloads.length == undefined)
            {
                debugger;
            }
            overloads.push(localOverloads[i]);
        }
    }
    _addCorrections(modifications, localCorrections) {
        if (!modifications) {
            debugger;
            return;
        }
        if (!localCorrections) {
            debugger;
            return;
        }
        for (var ci = 0; ci < localCorrections.length; ci++) {
            modifications.push(localCorrections[ci]);
        }
    }
    addOverloads(status, tokenRuleResult) {
        if (status) {
            if (!tokenRuleResult)
            {
                debugger;
                return 0;
            }
            if (this.overloads) {
                this._addOverloads(tokenRuleResult.overloads, this.overloads);
            }
            if (this.modifications) {
                this._addCorrections(tokenRuleResult.modifications, this.modifications);
            }
        }
        return status;
    }
    match(token, params, tokenRuleResult) {
        debugger;
        return 0;
    }
}

class TokenRuleAttCondition extends TokenRuleCondition {
    constructor(json) {
        super(json);
        if (json.attribute)
        {
            this.attribute = json.attribute;
        }
        else{
            debugger;
        }
    }
    match(token, params, tokenRuleResult) {
        debugger;
        return 0;
    }
}

module.exports = {
    TokenRuleCondition: TokenRuleCondition,
    TokenRuleAttCondition: TokenRuleAttCondition
};
