/*
 * 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.chemical;

/**
 * Химическая формула
 */
public class ChemicalFormulaReferent extends com.pullenti.ner.Referent {

    public ChemicalFormulaReferent() {
        super(OBJ_TYPENAME);
        setInstanceOf(MetaChemical.GLOBALMETA);
    }

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

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

    /**
     * Имя атрибута - наименование формулы
     */
    public static final String ATTR_NAME = "NAME";

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

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


    public String getName() {
        return this.getStringValue(ATTR_NAME);
    }

    public String setName(String _value) {
        this.addSlot(ATTR_NAME, _value, true, 0);
        return _value;
    }


    @Override
    public String toStringEx(boolean shortVariant, com.pullenti.morph.MorphLang lang, int lev) {
        String res = getValue();
        if (res == null) {
            String nam = getName();
            if (nam == null) 
                return "?";
            return nam.toLowerCase();
        }
        if (!shortVariant && getName() != null) {
            java.util.ArrayList<String> names = this.getStringValues(ATTR_NAME);
            StringBuilder tmp = new StringBuilder();
            tmp.append(res).append(" (");
            for (int i = 0; i < names.size(); i++) {
                if (i > 0) 
                    tmp.append(", ");
                tmp.append(names.get(i).toLowerCase());
            }
            tmp.append(")");
            res = tmp.toString();
        }
        return res;
    }

    @Override
    public boolean canBeEquals(com.pullenti.ner.Referent obj, com.pullenti.ner.core.ReferentsEqualType typ) {
        ChemicalFormulaReferent cf = (ChemicalFormulaReferent)com.pullenti.unisharp.Utils.cast(obj, ChemicalFormulaReferent.class);
        if (cf == null) 
            return false;
        if (getValue() != null && cf.getValue() != null) 
            return com.pullenti.unisharp.Utils.stringsEq(getValue(), cf.getValue());
        if (getName() != null && cf.getName() != null) 
            return com.pullenti.unisharp.Utils.stringsEq(getName(), cf.getName());
        return false;
    }

    @Override
    public com.pullenti.ner.core.IntOntologyItem createOntologyItem() {
        com.pullenti.ner.core.IntOntologyItem oi = new com.pullenti.ner.core.IntOntologyItem(this);
        oi.termins.add(new com.pullenti.ner.core.Termin((String)com.pullenti.unisharp.Utils.notnull(getValue(), getName()), null, false));
        return oi;
    }
}
