/*
 * SDK Pullenti Lingvo, version 4.33, fabruary 2026. Copyright (c) 2013-2026, Pullenti. All rights reserved. 
 * Non-Commercial Freeware and Commercial Software.
 * This class is generated using the converter Unisharping (www.unisharping.ru) from Pullenti C#.NET project. 
 * The latest version of the code is available on the site www.pullenti.ru
 */

const Utils = require("./../../../unisharp/Utils");
const RefOutArgWrapper = require("./../../../unisharp/RefOutArgWrapper");

const GetTextAttr = require("./../../core/GetTextAttr");
const NumberToken = require("./../../NumberToken");
const BracketParseAttr = require("./../../core/BracketParseAttr");
const PartTokenItemType = require("./PartTokenItemType");
const MiscHelper = require("./../../core/MiscHelper");
const DecreeChangeKind = require("./../DecreeChangeKind");
const DecreeChangeReferent = require("./../DecreeChangeReferent");
const NumberHelper = require("./../../core/NumberHelper");
const NumberExType = require("./../../core/NumberExType");
const BracketHelper = require("./../../core/BracketHelper");
const MoneyReferent = require("./../../money/MoneyReferent");
const MetaToken = require("./../../MetaToken");
const DecreeKind = require("./../DecreeKind");
const DecreeTokenItemType = require("./DecreeTokenItemType");
const ReferentToken = require("./../../ReferentToken");
const DecreeReferent = require("./../DecreeReferent");
const DecreePartReferent = require("./../DecreePartReferent");
const DecreeToken = require("./DecreeToken");
const PartToken = require("./PartToken");
const CanonicDecreeRefUri = require("./CanonicDecreeRefUri");

// Некоторые полезные функции для НПА
class DecreeHelper {
    
    static parseDateTime(str) {
        if (Utils.isNullOrEmpty(str)) 
            return null;
        try {
            let prts = Utils.splitString(str, '.', false);
            let y = 0;
            let wrapy1110 = new RefOutArgWrapper();
            let inoutres1111 = Utils.tryParseInt(prts[0], wrapy1110);
            y = wrapy1110.value;
            if (!inoutres1111) 
                return null;
            let mon = 0;
            let day = 0;
            if (prts.length > 1) {
                let wrapmon1108 = new RefOutArgWrapper();
                let inoutres1109 = Utils.tryParseInt(prts[1], wrapmon1108);
                mon = wrapmon1108.value;
                if (inoutres1109) {
                    if (prts.length > 2) {
                        let wrapday1107 = new RefOutArgWrapper();
                        Utils.tryParseInt(prts[2], wrapday1107);
                        day = wrapday1107.value;
                    }
                }
            }
            if (mon <= 0) 
                mon = 1;
            if (day <= 0) 
                day = 1;
            if (y > 3000 || (y < 1)) 
                return null;
            if (day > Utils.daysInMonth(y, mon)) 
                day = Utils.daysInMonth(y, mon);
            return new Date(y, mon - 1, day, 0, 0, 0);
        } catch (ex) {
        }
        return null;
    }
    
    static tryCreateCanonicDecreeRefUri(t) {
        if (!(t instanceof ReferentToken)) 
            return null;
        let dr = Utils.as(t.getReferent(), DecreeReferent);
        let res = null;
        if (dr !== null) {
            if (dr.kind === DecreeKind.PUBLISHER) 
                return null;
            res = CanonicDecreeRefUri._new1112(t.kit.sofa.text, dr, t.beginChar, t.endChar);
            if ((t.previous !== null && t.previous.isChar('(') && t.next !== null) && t.next.isChar(')')) 
                return res;
            if (t.miscAttrs !== 0) 
                return res;
            let rt = Utils.as(t, ReferentToken);
            if (rt.beginToken.isChar('(') && rt.endToken.isChar(')')) {
                res = CanonicDecreeRefUri._new1112(t.kit.sofa.text, dr, rt.beginToken.next.beginChar, rt.endToken.previous.endChar);
                return res;
            }
            let nextDecreeItems = null;
            if ((t.next !== null && t.next.isCommaAnd && (t.next.next instanceof ReferentToken)) && (t.next.next.getReferent() instanceof DecreeReferent)) {
                nextDecreeItems = DecreeToken.tryAttachList(t.next.next.beginToken, null, 10, false);
                if (nextDecreeItems !== null && nextDecreeItems.length > 1) {
                    for (let i = 0; i < (nextDecreeItems.length - 1); i++) {
                        if (nextDecreeItems[i].isNewlineAfter) {
                            nextDecreeItems.splice(i + 1, nextDecreeItems.length - i - 1);
                            break;
                        }
                    }
                }
            }
            let wasTyp = false;
            let wasNum = false;
            for (let tt = t.beginToken; tt !== null && tt.endChar <= t.endChar; tt = tt.next) {
                if (tt.beginChar === t.beginChar && tt.isChar('(') && tt.next !== null) 
                    res.beginChar = tt.next.beginChar;
                if (tt.isChar('(') && tt.next !== null && tt.next.isValue("ДАЛЕЕ", null)) {
                    if (res.endChar >= tt.beginChar) 
                        res.endChar = tt.previous.endChar;
                    break;
                }
                if (tt.endChar === t.endChar && tt.isChar(')')) {
                    res.endChar = tt.previous.endChar;
                    for (let tt1 = tt.previous; tt1 !== null && tt1.beginChar >= res.beginChar; tt1 = tt1.previous) {
                        if (tt1.isChar('(') && tt1.previous !== null) {
                            if (res.beginChar < tt1.previous.beginChar) 
                                res.endChar = tt1.previous.endChar;
                        }
                    }
                }
                let li = DecreeToken.tryAttachList(tt, null, 10, false);
                if (li !== null && li.length > 0) {
                    for (let ii = 0; ii < (li.length - 1); ii++) {
                        if (li[ii].typ === DecreeTokenItemType.TYP && li[ii + 1].typ === DecreeTokenItemType.TERR) 
                            res.typeWithGeo = MiscHelper.getTextValue(li[ii].beginToken, li[ii + 1].endToken, GetTextAttr.FIRSTNOUNGROUPTONOMINATIVESINGLE);
                    }
                    if ((nextDecreeItems !== null && nextDecreeItems.length > 1 && (nextDecreeItems.length < li.length)) && nextDecreeItems[0].typ !== DecreeTokenItemType.TYP) {
                        let d = li.length - nextDecreeItems.length;
                        let j = 0;
                        for (j = 0; j < nextDecreeItems.length; j++) {
                            if (nextDecreeItems[j].typ !== li[d + j].typ) 
                                break;
                        }
                        if (j >= nextDecreeItems.length) {
                            li.splice(0, d);
                            res.beginChar = li[0].beginChar;
                        }
                    }
                    else if ((nextDecreeItems !== null && nextDecreeItems.length === 1 && nextDecreeItems[0].typ === DecreeTokenItemType.NAME) && li.length === 2 && li[1].typ === DecreeTokenItemType.NAME) {
                        res.beginChar = li[1].beginChar;
                        res.endChar = li[1].endChar;
                        break;
                    }
                    else if ((nextDecreeItems !== null && nextDecreeItems.length === 1 && nextDecreeItems[0].typ === DecreeTokenItemType.NUMBER) && li[li.length - 1].typ === DecreeTokenItemType.NUMBER) {
                        res.beginChar = li[li.length - 1].beginChar;
                        res.endChar = li[li.length - 1].endChar;
                    }
                    for (let i = 0; i < li.length; i++) {
                        let l = li[i];
                        if (l.beginChar > t.endChar) {
                            li.splice(i, li.length - i);
                            break;
                        }
                        if (l.typ === DecreeTokenItemType.NAME) {
                            if (!wasNum) {
                                if (dr.kind === DecreeKind.CONTRACT) 
                                    continue;
                                if (((i + 1) < li.length) && ((li[i + 1].typ === DecreeTokenItemType.DATE || li[i + 1].typ === DecreeTokenItemType.NUMBER))) 
                                    continue;
                            }
                            let ee = l.beginToken.previous.endChar;
                            if (ee > res.beginChar && (ee < res.endChar)) 
                                res.endChar = ee;
                            break;
                        }
                        if (l.typ === DecreeTokenItemType.NUMBER) 
                            wasNum = true;
                        if (i === 0) {
                            if (l.typ === DecreeTokenItemType.TYP) 
                                wasTyp = true;
                            else if (l.typ === DecreeTokenItemType.OWNER || l.typ === DecreeTokenItemType.ORG) {
                                if (((i + 1) < li.length) && ((li[1].typ === DecreeTokenItemType.DATE || li[1].typ === DecreeTokenItemType.NUMBER))) 
                                    wasTyp = true;
                            }
                            if (wasTyp) {
                                let tt0 = l.beginToken.previous;
                                if (tt0 !== null && tt0.isChar('.')) 
                                    tt0 = tt0.previous;
                                if (tt0 !== null && ((tt0.isValue("УТВЕРЖДЕННЫЙ", null) || tt0.isValue("УТВЕРДИТЬ", null) || tt0.isValue("УТВ", null)))) {
                                    if (l.beginChar > res.beginChar) {
                                        res.beginChar = l.beginChar;
                                        if (res.endChar < res.beginChar) 
                                            res.endChar = t.endChar;
                                        res.isAdopted = true;
                                    }
                                }
                            }
                        }
                    }
                    if (li.length > 0) {
                        tt = li[li.length - 1].endToken;
                        if (tt.isChar(')')) 
                            tt = tt.previous;
                        continue;
                    }
                }
                if (wasTyp) {
                    let na = DecreeToken.tryAttachName(tt, dr.typ0, true, false, false);
                    if (na !== null && tt.beginChar > t.beginChar) {
                        let tt1 = na.endToken.next;
                        if (tt1 !== null && tt1.isCharOf(",()")) 
                            tt1 = tt1.next;
                        if (tt1 !== null && (tt1.endChar < t.endChar)) {
                            if (tt1.isValue("УТВЕРЖДЕННЫЙ", null) || tt1.isValue("УТВЕРДИТЬ", null) || tt1.isValue("УТВ", null)) {
                                tt = tt1;
                                continue;
                            }
                        }
                        if (tt.previous !== null && tt.previous.isChar(':') && na.endChar <= res.endChar) {
                            res.beginChar = tt.beginChar;
                            break;
                        }
                        if (tt.previous.endChar > res.beginChar) {
                            res.endChar = tt.previous.endChar;
                            break;
                        }
                    }
                }
            }
            return res;
        }
        let dpr = Utils.as(t.getReferent(), DecreePartReferent);
        if (dpr === null) 
            return null;
        if ((t.previous !== null && t.previous.isHiphen && (t.previous.previous instanceof ReferentToken)) && (t.previous.previous.getReferent() instanceof DecreePartReferent)) {
            if (DecreePartReferent.createRangeReferent(Utils.as(t.previous.previous.getReferent(), DecreePartReferent), dpr) !== null) 
                return null;
        }
        let t1 = t;
        let hasDiap = false;
        let diapRef = null;
        if ((t.next !== null && t.next.isHiphen && (t.next.next instanceof ReferentToken)) && (t.next.next.getReferent() instanceof DecreePartReferent)) {
            let diap = DecreePartReferent.createRangeReferent(Utils.as(dpr, DecreePartReferent), Utils.as(t.next.next.getReferent(), DecreePartReferent));
            if (diap !== null) {
                dpr = diap;
                hasDiap = true;
                t1 = t.next.next;
                diapRef = Utils.as(t1, ReferentToken);
            }
        }
        res = CanonicDecreeRefUri._new1114(t.kit.sofa.text, dpr, t.beginChar, t1.endChar, hasDiap);
        if ((t.previous !== null && t.previous.isChar('(') && t1.next !== null) && t1.next.isChar(')')) 
            return res;
        for (let tt = t.beginToken; tt !== null && tt.endChar <= t.endChar; tt = tt.next) {
            if (tt.getReferent() instanceof DecreeReferent) {
                if (tt.beginChar > t.beginChar) {
                    res.endChar = tt.previous.endChar;
                    if (tt.previous.morph._class.isPreposition && tt.previous.previous !== null) 
                        res.endChar = tt.previous.previous.endChar;
                }
                else if (tt.endChar < t.endChar) 
                    res.beginChar = tt.beginChar;
                break;
            }
        }
        let hasSameBefore = DecreeHelper._hasSameDecree(t, dpr, true);
        let hasSameAfter = DecreeHelper._hasSameDecree(t, dpr, false);
        let ptmin = PartTokenItemType.PREFIX;
        let ptmin2 = PartTokenItemType.PREFIX;
        let max = 0;
        let max2 = 0;
        for (const s of dpr.slots) {
            let pt = PartToken._getTypeByAttrName(s.typeName);
            if (pt === PartTokenItemType.PREFIX) 
                continue;
            let co = PartToken._getRank(pt);
            if (co < 1) {
                if (pt === PartTokenItemType.PART && dpr.findSlot(DecreePartReferent.ATTR_CLAUSE, null, true) !== null) 
                    co = PartToken._getRank(PartTokenItemType.PARAGRAPH);
                else 
                    continue;
            }
            if (co > max) {
                max2 = max;
                ptmin2 = ptmin;
                max = co;
                ptmin = pt;
            }
            else if (co > max2) {
                max2 = co;
                ptmin2 = pt;
            }
        }
        if (ptmin !== PartTokenItemType.PREFIX) {
            for (let tt = t.beginToken; tt !== null && tt.endChar <= res.endChar; tt = tt.next) {
                if (tt.beginChar >= res.beginChar) {
                    let pt = PartToken.tryAttach(tt, null, false, false);
                    if (pt !== null && pt.typ === ptmin) {
                        res.beginChar = pt.beginChar;
                        res.endChar = pt.endChar;
                        if (pt.typ === PartTokenItemType.APPENDIX && pt.endToken.isValue("К", null) && pt.beginToken !== pt.endToken) 
                            res.endChar = pt.endToken.previous.endChar;
                        if (pt.endChar === t.endChar) {
                            if ((t.next !== null && t.next.isCommaAnd && (t.next.next instanceof ReferentToken)) && (t.next.next.getReferent() instanceof DecreePartReferent)) {
                                let tt1 = t.next.next.beginToken;
                                let ok = true;
                                if (tt1.chars.isLetter) 
                                    ok = false;
                                if (ok) {
                                    for (const v of pt.values) {
                                        res.beginChar = v.beginChar;
                                        res.endChar = v.endChar;
                                        break;
                                    }
                                }
                            }
                        }
                        if (!hasDiap) 
                            return res;
                        break;
                    }
                }
            }
            if (hasDiap && diapRef !== null) {
                for (let tt = diapRef.beginToken; tt !== null && tt.endChar <= diapRef.endChar; tt = tt.next) {
                    if (tt.isChar(',')) 
                        break;
                    if (tt !== diapRef.beginToken && tt.isWhitespaceBefore) 
                        break;
                    res.endChar = tt.endChar;
                }
                return res;
            }
        }
        if (((hasSameBefore || hasSameAfter)) && ptmin !== PartTokenItemType.PREFIX) {
            for (let tt = t.beginToken; tt !== null && tt.endChar <= res.endChar; tt = tt.next) {
                if (tt.beginChar >= res.beginChar) {
                    let pt = (!hasSameBefore ? PartToken.tryAttach(tt, null, false, false) : null);
                    if (pt !== null) {
                        if (pt.typ === ptmin) {
                            for (const v of pt.values) {
                                res.beginChar = v.beginChar;
                                res.endChar = v.endChar;
                                return res;
                            }
                        }
                        tt = pt.endToken;
                        continue;
                    }
                    if ((tt instanceof NumberToken) && tt.beginChar === res.beginChar) {
                        res.endChar = tt.endChar;
                        for (; tt !== null && tt.next !== null; ) {
                            if (!tt.next.isChar('.') || tt.isWhitespaceAfter || tt.next.isWhitespaceAfter) 
                                break;
                            if (!(tt.next.next instanceof NumberToken)) 
                                break;
                            tt = tt.next.next;
                            res.endChar = tt.endChar;
                        }
                        if (tt.next !== null && tt.next.isHiphen) {
                            if (tt.next.next instanceof NumberToken) {
                                tt = tt.next.next;
                                res.endChar = tt.endChar;
                                for (; tt !== null && tt.next !== null; ) {
                                    if (!tt.next.isChar('.') || tt.isWhitespaceAfter || tt.next.isWhitespaceAfter) 
                                        break;
                                    if (!(tt.next.next instanceof NumberToken)) 
                                        break;
                                    tt = tt.next.next;
                                    res.endChar = tt.endChar;
                                }
                            }
                            else if (tt.next.next !== null && (tt.next.next.getReferent() instanceof DecreePartReferent) && hasDiap) 
                                res.endChar = tt.next.next.beginToken.endChar;
                        }
                        return res;
                    }
                    if (BracketHelper.canBeStartOfSequence(tt, true, false) && tt.beginChar === res.beginChar && hasSameBefore) {
                        let br = BracketHelper.tryParse(tt, BracketParseAttr.NO, 100);
                        if (br !== null && br.endToken.previous === tt.next) {
                            res.endChar = br.endChar;
                            return res;
                        }
                    }
                }
            }
            return res;
        }
        if (!hasSameBefore && !hasSameAfter && ptmin !== PartTokenItemType.PREFIX) {
            for (let tt = t.beginToken; tt !== null && tt.endChar <= res.endChar; tt = tt.next) {
                if (tt.beginChar >= res.beginChar) {
                    let pts = PartToken.tryAttachList(tt, false, 40);
                    if (pts === null || pts.length === 0) 
                        break;
                    for (let i = 0; i < pts.length; i++) {
                        if (pts[i].typ === ptmin) {
                            res.beginChar = pts[i].beginChar;
                            res.endChar = pts[i].endChar;
                            tt = pts[i].endToken;
                            if (tt.next !== null && tt.next.isHiphen) {
                                if (tt.next.next instanceof NumberToken) 
                                    res.endChar = tt.next.next.endChar;
                                else if (tt.next.next !== null && (tt.next.next.getReferent() instanceof DecreePartReferent) && hasDiap) 
                                    res.endChar = tt.next.next.beginToken.endChar;
                            }
                            return res;
                        }
                    }
                }
            }
        }
        return res;
    }
    
    static _hasSameDecree(t, dpr, before) {
        if (((before ? t.previous : t.next)) === null) 
            return false;
        t = (before ? t.previous : t.next);
        if (t.isCommaAnd || t.morph._class.isConjunction) {
        }
        else 
            return false;
        t = (before ? t.previous : t.next);
        if (t === null) 
            return false;
        let dpr0 = Utils.as(t.getReferent(), DecreePartReferent);
        if (dpr0 === null) 
            return false;
        if (dpr0.owner !== dpr.owner) 
            return false;
        if (dpr0.owner === null) {
            if (dpr0.localTyp !== dpr.localTyp) 
                return false;
        }
        for (const s of dpr0.slots) {
            if (PartToken._getTypeByAttrName(s.typeName) !== PartTokenItemType.PREFIX) {
                if (dpr.findSlot(s.typeName, null, true) === null) 
                    return false;
            }
        }
        for (const s of dpr.slots) {
            if (PartToken._getTypeByAttrName(s.typeName) !== PartTokenItemType.PREFIX) {
                if (dpr0.findSlot(s.typeName, null, true) === null) 
                    return false;
            }
        }
        return true;
    }
    
    static _outMoney(m) {
        let res = m.toString();
        res = Utils.replaceString(Utils.replaceString(Utils.replaceString(res, '.', ' '), "RUR", "руб."), "RUB", "руб.");
        return res;
    }
    
    static checkNds(t, nds = 18, ndsMustbeMoney = false) {
        if (t === null || nds <= 0) 
            return null;
        let m = Utils.as(t.getReferent(), MoneyReferent);
        if (m === null) 
            return null;
        let hasNds = false;
        let hasNdsPerc = false;
        let hasAll = false;
        let incl = false;
        let tt = null;
        let m1 = null;
        let ndsT0 = null;
        let ndsT1 = null;
        for (tt = t.next; tt !== null; tt = tt.next) {
            if (tt.isValue("НДС", null)) {
                hasNds = true;
                ndsT0 = (ndsT1 = tt);
                continue;
            }
            if (tt instanceof ReferentToken) {
                m1 = Utils.as(tt.getReferent(), MoneyReferent);
                break;
            }
            if (tt instanceof NumberToken) {
                let ne = NumberHelper.tryParseNumberWithPostfix(tt);
                if (ne !== null && ne.exTyp === NumberExType.PERCENT) {
                    if (Math.abs(ne.realValue - nds) > 0.0001) {
                        let ok = false;
                        if (hasNds) 
                            ok = true;
                        if (ok) 
                            return MetaToken._new663(tt, ne.endToken, ("Размер НДС должен быть " + nds + "%, а не " + ne.realValue + "%"));
                    }
                    tt = (ndsT1 = ne.endToken);
                    hasNdsPerc = true;
                    continue;
                }
            }
            if (tt.isValue("ВСЕГО", null)) {
                hasAll = true;
                continue;
            }
            if (tt.isValue("ТОМ", null) || tt.isValue("ЧИСЛО", null) || tt.isValue("ВКЛЮЧАЯ", null)) {
                incl = true;
                continue;
            }
            if ((tt.isValue("КРОМЕ", null) || tt.isValue("ТОГО", null) || tt.isValue("РАЗМЕР", null)) || tt.isValue("СУММА", null) || tt.isValue("СТАВКА", null)) 
                continue;
            if (((tt.isValue("Т", null) && tt.next !== null && tt.next.isChar('.')) && tt.next.next !== null && tt.next.next.isValue("Ч", null)) && tt.next.next.next !== null && tt.next.next.next.isChar('.')) {
                incl = true;
                tt = tt.next.next.next;
                continue;
            }
            if (!tt.chars.isLetter || tt.morph._class.isPreposition) 
                continue;
            break;
        }
        if (!hasNds) 
            return null;
        if (m1 === null) {
            if (ndsMustbeMoney) 
                return MetaToken._new663(ndsT0, ndsT1, "Размер НДС должен быть в денежном выражении");
            return null;
        }
        if (hasAll) 
            return null;
        let mustBe = m.realValue;
        mustBe = mustBe * ((nds / (100)));
        if (incl) 
            mustBe /= (((1) + ((nds / (100)))));
        let dd = mustBe * (100);
        dd -= (Math.floor(dd));
        dd /= (100);
        mustBe -= dd;
        if (dd >= 0.005) 
            mustBe += 0.01;
        let real = m1.realValue;
        let delta = mustBe - real;
        if (delta < 0) 
            delta = -delta;
        if (delta > 0.011) {
            if ((delta < 1) && m1.rest === 0 && m.rest === 0) {
            }
            else {
                let mr = MoneyReferent._new1117(m1.currency, mustBe);
                return MetaToken._new663(t, tt, ("Размер НДС должен быть " + DecreeHelper._outMoney(mr) + ", а не " + DecreeHelper._outMoney(m1)));
            }
        }
        if (incl) 
            return null;
        let m2 = null;
        hasAll = false;
        for (tt = tt.next; tt !== null; tt = tt.next) {
            if (tt instanceof ReferentToken) {
                m2 = Utils.as(tt.getReferent(), MoneyReferent);
                break;
            }
            if (!tt.chars.isLetter || tt.morph._class.isPreposition) 
                continue;
            if (tt.isValue("ВСЕГО", null)) {
                hasAll = true;
                continue;
            }
            if (tt.isValue("НДС", null) || tt.isValue("ВМЕСТЕ", null)) 
                continue;
            break;
        }
        if (m2 !== null && hasAll) {
            mustBe = m.realValue + m1.realValue;
            delta = mustBe - m2.realValue;
            if (delta < 0) 
                delta = -delta;
            if (delta > 0.01) {
                let mr = MoneyReferent._new1117(m1.currency, mustBe);
                let err = ("Всего с НДС должно быть " + DecreeHelper._outMoney(mr) + ", а не " + DecreeHelper._outMoney(m2));
                return MetaToken._new663(t, tt, err);
            }
        }
        return null;
    }
    
    static removePsevdoDecreeparts(kit) {
        if (kit.miscData.containsKey("RemovePsevdoDecreeparts")) 
            return kit.miscData.get("RemovePsevdoDecreeparts");
        let cou = 0;
        for (let t = kit.firstToken; t !== null; t = t.next) {
            if (t.isNewlineBefore && t.isNewlineAfter) {
                if (t.getReferent() instanceof DecreePartReferent) {
                    let tt = t.next;
                    if (tt === null) 
                        continue;
                    if (tt.isValue("ВВЕСТИ", null) || tt.isCommaAnd) 
                        continue;
                    t = kit.debedToken(t);
                    cou++;
                    continue;
                }
            }
            if (t.isNewlineBefore && (t.getReferent() instanceof DecreeChangeReferent)) {
                let dch = Utils.as(t.getReferent(), DecreeChangeReferent);
                if (dch.kind === DecreeChangeKind.CONTAINER) {
                    if ((t.beginToken.isValue("ИЗМЕНЕНИЕ", null) || t.beginToken.isValue("ПЕРЕЧЕНЬ", null) || t.beginToken.isValue("О", null)) || t.beginToken.isValue("В", null) || (t.beginToken instanceof ReferentToken)) {
                        t = t.kit.debedToken(t);
                        cou++;
                        continue;
                    }
                }
            }
        }
        if ((kit.firstToken instanceof ReferentToken) && kit.firstToken.getReferent().typeName === "ORGANIZATION" && kit.firstToken.isNewlineAfter) {
            if ((kit.firstToken.next instanceof ReferentToken) && (kit.firstToken.next.getReferent() instanceof DecreeReferent)) {
                kit.debedToken(kit.firstToken.next);
                cou++;
            }
        }
        kit.miscData.put("RemovePsevdoDecreeparts", cou);
        return cou;
    }
}


module.exports = DecreeHelper