/*
 * 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 StringBuilder = require("./../../unisharp/StringBuilder");

const DecreeChangeValueKind = require("./DecreeChangeValueKind");
const ReferentsEqualType = require("./../core/ReferentsEqualType");
const Referent = require("./../Referent");
const ReferentClass = require("./../metadata/ReferentClass");
const DecreePartReferent = require("./DecreePartReferent");
const MetaDecreeChangeValue = require("./internal/MetaDecreeChangeValue");

/**
 * Значение изменения структурного элемента НПА
 */
class DecreeChangeValueReferent extends Referent {
    
    constructor() {
        super(DecreeChangeValueReferent.OBJ_TYPENAME);
        this.isContent = false;
        this.instanceOf = MetaDecreeChangeValue.GLOBAL_META;
    }
    
    toStringEx(shortVariant, lang = null, lev = 0) {
        let res = new StringBuilder();
        let nws = this.newItems;
        if (nws.length > 0) {
            for (const p of nws) {
                let dpr = new DecreePartReferent();
                let ii = p.indexOf(' ');
                if (ii < 0) 
                    dpr.addSlot(p, "", false, 0);
                else 
                    dpr.addSlot(p.substring(0, 0 + ii), p.substring(ii + 1), false, 0);
                res.append(" новый '").append(dpr.toStringEx(true, null, 0)).append("'");
            }
        }
        if (this.kind !== DecreeChangeValueKind.UNDEFINED) 
            res.append(" ").append(MetaDecreeChangeValue.KIND_FEATURE.convertInnerValueToOuterValue(this.kind.toString(), lang).toString().toLowerCase());
        let vals = this.getStringValues(DecreeChangeValueReferent.ATTR_VALUE);
        if (vals !== null && vals.length > 0) {
            res.append(" ");
            for (let i = 0; i < vals.length; i++) {
                if (i > 0) 
                    res.append(", ");
                let val = vals[i];
                if (val.length > 100) 
                    val = val.substring(0, 0 + 100) + "...";
                res.append("'").append(val).append("'");
                res.replace('\n', ' ');
                res.replace('\r', ' ');
            }
        }
        return res.toString().trim();
    }
    
    get kind() {
        let s = this.getStringValue(DecreeChangeValueReferent.ATTR_KIND);
        if (s === null) 
            return DecreeChangeValueKind.UNDEFINED;
        try {
            if (s === "Footnote") 
                return DecreeChangeValueKind.UNDEFINED;
            let res = DecreeChangeValueKind.of(s);
            if (res instanceof DecreeChangeValueKind) 
                return DecreeChangeValueKind.of(res);
        } catch (ex1472) {
        }
        return DecreeChangeValueKind.UNDEFINED;
    }
    set kind(_value) {
        if (_value !== DecreeChangeValueKind.UNDEFINED) 
            this.addSlot(DecreeChangeValueReferent.ATTR_KIND, _value.toString(), true, 0);
        return _value;
    }
    
    get value() {
        return this.getStringValue(DecreeChangeValueReferent.ATTR_VALUE);
    }
    set value(_value) {
        this.addSlot(DecreeChangeValueReferent.ATTR_VALUE, _value, true, 0);
        return _value;
    }
    
    get newItems() {
        let res = new Array();
        for (const s of this.slots) {
            if (s.typeName === DecreeChangeValueReferent.ATTR_NEWITEM && ((typeof s.value === 'string' || s.value instanceof String))) 
                res.push(Utils.asString(s.value));
        }
        return res;
    }
    
    get beginChar() {
        let val = this.getStringValue(DecreeChangeValueReferent.ATTR_BEGINCHAR);
        if (val === null) 
            return 0;
        let n = 0;
        let wrapn1473 = new RefOutArgWrapper();
        let inoutres1474 = Utils.tryParseInt(val, wrapn1473);
        n = wrapn1473.value;
        if (inoutres1474) 
            return n;
        return 0;
    }
    set beginChar(_value) {
        this.addSlot(DecreeChangeValueReferent.ATTR_BEGINCHAR, _value.toString(), true, 0);
        return _value;
    }
    
    get endChar() {
        let val = this.getStringValue(DecreeChangeValueReferent.ATTR_ENDCHAR);
        if (val === null) 
            return 0;
        let n = 0;
        let wrapn1475 = new RefOutArgWrapper();
        let inoutres1476 = Utils.tryParseInt(val, wrapn1475);
        n = wrapn1475.value;
        if (inoutres1476) 
            return n;
        return 0;
    }
    set endChar(_value) {
        this.addSlot(DecreeChangeValueReferent.ATTR_ENDCHAR, _value.toString(), true, 0);
        return _value;
    }
    
    canBeEquals(obj, typ = ReferentsEqualType.WITHINONETEXT) {
        return obj === this;
    }
    
    static _new1049(_arg1) {
        let res = new DecreeChangeValueReferent();
        res.kind = _arg1;
        return res;
    }
    
    static static_constructor() {
        DecreeChangeValueReferent.OBJ_TYPENAME = "DECREECHANGEVALUE";
        DecreeChangeValueReferent.ATTR_KIND = "KIND";
        DecreeChangeValueReferent.ATTR_VALUE = "VALUE";
        DecreeChangeValueReferent.ATTR_NEWITEM = "NEWITEM";
        DecreeChangeValueReferent.ATTR_BEGINCHAR = "BEGIN";
        DecreeChangeValueReferent.ATTR_ENDCHAR = "END";
    }
}


DecreeChangeValueReferent.static_constructor();

module.exports = DecreeChangeValueReferent