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

/**
 * Возможное значение номера
 */
class SingleNumValue {
    
    constructor() {
        this.typ = SingleNumValueType.DIGIT;
        this.val = 0;
        this.letter = '\0';
        this.upper = false;
    }
    
    toString() {
        if (this.typ === SingleNumValueType.DIGIT) 
            return this.val.toString();
        if (this.typ === SingleNumValueType.ROMAN) 
            return ("rom(" + this.val + ")");
        return (this.letter);
    }
    
    get isOne() {
        if (this.val === 1) 
            return true;
        if ((this.letter === 'A' || this.letter === 'А' || this.letter === 'a') || this.letter === 'а') 
            return true;
        return false;
    }
    
    toInt() {
        if (this.typ !== SingleNumValueType.LETTER) 
            return this.val;
        if (!Utils.isLetter(this.letter)) 
            return -1;
        if ((this.letter.charCodeAt(0)) < 0x80) {
            if (Utils.isUpperCase(this.letter)) 
                return (((this.letter.charCodeAt(0)) - ('A'.charCodeAt(0))) + 1);
            else 
                return (((this.letter.charCodeAt(0)) - ('a'.charCodeAt(0))) + 1);
        }
        else {
            let ch = this.letter.toUpperCase();
            let i = "АБВГДЕЖЗИКЛМНОПРСТУФХЦЧШЩЫЭЮЯ".indexOf(ch);
            if (i >= 0) 
                return i + 1;
            return -1;
        }
    }
}


module.exports = SingleNumValue