import { assert } from "../assert.js";

/**
 * Represents information about a language
 */
export class LanguageMetadata {
    /**
     * Measured in characters per second
     * @type {number}
     */
    reading_speed = 10

    /**
     * Ordered list of fallback languages, if no value is found for a key in this language, other languages will be attempted in order
     * Identified by localization key
     * @see {@link #locale}
     * @type {string[]}
     */
    fallback_languages = []

    /**
     * Localization key,
     * @see ISO 639
     * @type {string}
     */
    locale = "";

    fromJSON({
                 reading_speed = 10,
                 fallback_languages = []
             }) {

        assert.isNumber(reading_speed, 'reading_speed');
        assert.greaterThan(reading_speed, 0, 'reading_speed');

        this.reading_speed = reading_speed;

        this.fallback_languages = fallback_languages;
    }

    static fromJSON(j) {
        const r = new LanguageMetadata();

        r.fromJSON(j);

        return r;
    }
}
