/*
 * 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# project. 
 * The latest version of the code is available on the site www.pullenti.ru
 */

package com.pullenti.ner.decree;

/**
 * Значение изменения структурного элемента НПА
 */
public class DecreeChangeValueReferent extends com.pullenti.ner.Referent {

    public DecreeChangeValueReferent() {
        super(OBJ_TYPENAME);
        setInstanceOf(com.pullenti.ner.decree.internal.MetaDecreeChangeValue.GLOBALMETA);
    }

    /**
     * Имя типа сущности TypeName ("DECREECHANGEVALUE")
     */
    public static final String OBJ_TYPENAME = "DECREECHANGEVALUE";

    /**
     * Имя атрибута - тип (DecreeChangeValueKind)
     */
    public static final String ATTR_KIND = "KIND";

    /**
     * Имя атрибута - значение
     */
    public static final String ATTR_VALUE = "VALUE";

    /**
     * Имя атрибута - новый структурный элемент
     */
    public static final String ATTR_NEWITEM = "NEWITEM";

    /**
     * Начальная позиция текста (сразу за кавычкой)
     */
    public static final String ATTR_BEGINCHAR = "BEGIN";

    /**
     * Конечная позиция текста (сразу перед закрывающей кавычкой)
     */
    public static final String ATTR_ENDCHAR = "END";

    @Override
    public String toStringEx(boolean shortVariant, com.pullenti.morph.MorphLang lang, int lev) {
        StringBuilder res = new StringBuilder();
        java.util.ArrayList<String> nws = getNewItems();
        if (nws.size() > 0) {
            for (String p : nws) {
                DecreePartReferent dpr = new DecreePartReferent();
                int 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 (getKind() != DecreeChangeValueKind.UNDEFINED) 
            res.append(" ").append(com.pullenti.ner.decree.internal.MetaDecreeChangeValue.KINDFEATURE.convertInnerValueToOuterValue(this.getKind().toString(), lang).toString().toLowerCase());
        java.util.ArrayList<String> vals = this.getStringValues(ATTR_VALUE);
        if (vals != null && vals.size() > 0) {
            res.append(" ");
            for (int i = 0; i < vals.size(); i++) {
                if (i > 0) 
                    res.append(", ");
                String val = vals.get(i);
                if (val.length() > 100) 
                    val = val.substring(0, 0 + 100) + "...";
                res.append("'").append(val).append("'");
                com.pullenti.unisharp.Utils.replace(res, '\n', ' ');
                com.pullenti.unisharp.Utils.replace(res, '\r', ' ');
            }
        }
        return res.toString().trim();
    }

    public DecreeChangeValueKind getKind() {
        String s = this.getStringValue(ATTR_KIND);
        if (s == null) 
            return DecreeChangeValueKind.UNDEFINED;
        try {
            if (com.pullenti.unisharp.Utils.stringsEq(s, "Footnote")) 
                return DecreeChangeValueKind.UNDEFINED;
            Object res = DecreeChangeValueKind.of(s);
            if (res instanceof DecreeChangeValueKind) 
                return (DecreeChangeValueKind)res;
        } catch (Exception ex1472) {
        }
        return DecreeChangeValueKind.UNDEFINED;
    }

    public DecreeChangeValueKind setKind(DecreeChangeValueKind _value) {
        if (_value != DecreeChangeValueKind.UNDEFINED) 
            this.addSlot(ATTR_KIND, _value.toString(), true, 0);
        return _value;
    }


    public String getValue() {
        return this.getStringValue(ATTR_VALUE);
    }

    public String setValue(String _value) {
        this.addSlot(ATTR_VALUE, _value, true, 0);
        return _value;
    }


    public java.util.ArrayList<String> getNewItems() {
        java.util.ArrayList<String> res = new java.util.ArrayList<String>();
        for (com.pullenti.ner.Slot s : getSlots()) {
            if (com.pullenti.unisharp.Utils.stringsEq(s.getTypeName(), ATTR_NEWITEM) && (s.getValue() instanceof String)) 
                res.add((String)com.pullenti.unisharp.Utils.cast(s.getValue(), String.class));
        }
        return res;
    }


    public int getBeginChar() {
        String val = this.getStringValue(ATTR_BEGINCHAR);
        if (val == null) 
            return 0;
        int n;
        com.pullenti.unisharp.Outargwrapper<Integer> wrapn1473 = new com.pullenti.unisharp.Outargwrapper<Integer>();
        boolean inoutres1474 = com.pullenti.unisharp.Utils.parseInteger(val, 0, null, wrapn1473);
        n = (wrapn1473.value != null ? wrapn1473.value : 0);
        if (inoutres1474) 
            return n;
        return 0;
    }

    public int setBeginChar(int _value) {
        this.addSlot(ATTR_BEGINCHAR, ((Integer)_value).toString(), true, 0);
        return _value;
    }


    public int getEndChar() {
        String val = this.getStringValue(ATTR_ENDCHAR);
        if (val == null) 
            return 0;
        int n;
        com.pullenti.unisharp.Outargwrapper<Integer> wrapn1475 = new com.pullenti.unisharp.Outargwrapper<Integer>();
        boolean inoutres1476 = com.pullenti.unisharp.Utils.parseInteger(val, 0, null, wrapn1475);
        n = (wrapn1475.value != null ? wrapn1475.value : 0);
        if (inoutres1476) 
            return n;
        return 0;
    }

    public int setEndChar(int _value) {
        this.addSlot(ATTR_ENDCHAR, ((Integer)_value).toString(), true, 0);
        return _value;
    }


    @Override
    public boolean canBeEquals(com.pullenti.ner.Referent obj, com.pullenti.ner.core.ReferentsEqualType typ) {
        return obj == this;
    }

    public boolean isContent;

    public static DecreeChangeValueReferent _new1049(DecreeChangeValueKind _arg1) {
        DecreeChangeValueReferent res = new DecreeChangeValueReferent();
        res.setKind(_arg1);
        return res;
    }
}
