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

const SourceOfAnalysis = require("./../../SourceOfAnalysis");
const TextToken = require("./../../TextToken");
const MorphGender = require("./../../../morph/MorphGender");
const AnalysisKit = require("./../../core/AnalysisKit");
const PullentiNerPersonInternalResourceHelper = require("./PullentiNerPersonInternalResourceHelper");

class ShortNameHelper {
    
    static getShortnamesForName(name) {
        let res = new Array();
        for (const kp of ShortNameHelper.m_Shorts_Names.entries) {
            for (const v of kp.value) {
                if (v.name === name) {
                    if (!res.includes(kp.key)) 
                        res.push(kp.key);
                }
            }
        }
        return res;
    }
    
    static getNamesForShortname(shortname) {
        let res = [ ];
        let wrapres3455 = new RefOutArgWrapper();
        let inoutres3456 = ShortNameHelper.m_Shorts_Names.tryGetValue(shortname, wrapres3455);
        res = wrapres3455.value;
        if (!inoutres3456) 
            return null;
        else 
            return res;
    }
    
    static initialize() {
        if (ShortNameHelper.m_Inited) 
            return;
        ShortNameHelper.m_Inited = true;
        let obj = PullentiNerPersonInternalResourceHelper.getString("ShortNames.txt");
        if (obj !== null) {
            let kit = new AnalysisKit(new SourceOfAnalysis(obj));
            for (let t = kit.firstToken; t !== null; t = t.next) {
                if (t.isNewlineBefore) {
                    let g = (t.isValue("F", null) ? MorphGender.FEMINIE : MorphGender.MASCULINE);
                    t = t.next;
                    let nam = t.term;
                    let shos = new Array();
                    for (t = t.next; t !== null; t = t.next) {
                        if (t.isNewlineBefore) 
                            break;
                        else 
                            shos.push(t.term);
                    }
                    for (const s of shos) {
                        let li = null;
                        let wrapli3458 = new RefOutArgWrapper();
                        let inoutres3459 = ShortNameHelper.m_Shorts_Names.tryGetValue(s, wrapli3458);
                        li = wrapli3458.value;
                        if (!inoutres3459) 
                            ShortNameHelper.m_Shorts_Names.put(s, (li = new Array()));
                        li.push(ShortNameHelper.ShortnameVar._new3457(nam, g));
                    }
                    if (t === null) 
                        break;
                    t = t.previous;
                }
            }
        }
    }
    
    static static_constructor() {
        ShortNameHelper.m_Shorts_Names = new Hashtable();
        ShortNameHelper.m_Inited = false;
    }
}


ShortNameHelper.ShortnameVar = class  {
    
    constructor() {
        this.name = null;
        this.gender = MorphGender.UNDEFINED;
    }
    
    toString() {
        return this.name;
    }
    
    static _new3457(_arg1, _arg2) {
        let res = new ShortNameHelper.ShortnameVar();
        res.name = _arg1;
        res.gender = _arg2;
        return res;
    }
}


ShortNameHelper.static_constructor();

module.exports = ShortNameHelper