/**
 * @copyright Sister Software
 * @license AGPL-3.0
 * @author Teffen Ellis, et al.
 */
/**
 * Classification recognized by Mailwoman.
 */
export const Classifications = new Set([
    "adjacent",
    "alpha",
    "alphanumeric",
    "area",
    "chain",
    "country",
    "dependency",
    "directional",
    "end_token_single_character",
    "end_token",
    "given_name",
    "house_number",
    "intersection",
    "level_designator",
    "level",
    "locality",
    "middle_initial",
    "multistreet",
    "numeric",
    "ordinal",
    "person",
    "personal_suffix",
    "personal_title",
    "place",
    "postcode",
    "punctuation",
    "region",
    "road_type",
    "start_token",
    "stop_word",
    "street_name",
    "street_prefix",
    "street_proper_name",
    "street_suffix",
    "street",
    "surname",
    "toponym",
    "unit_designator",
    "unit",
    "unknown",
    "venue",
]);
const ClassificationConfidenceBias = new Map([["country", 0.9]]);
/**
 * Public classification labels.
 */
const VisibleClassification = new Set([
    "country",
    "dependency",
    "house_number",
    "level_designator",
    "level",
    "locality",
    "postcode",
    "region",
    "street",
    "unit_designator",
    "unit",
    "venue",
]);
export function isVisibleClassification(input) {
    const classification = typeof input === "string" ? input : input.classification;
    return VisibleClassification.has(classification);
}
/**
 * A map of classifications to matches.
 */
export class ClassificationsMatchMap extends Map {
    add(...args) {
        let match;
        if (typeof args[0] === "string") {
            const classification = args[0];
            const confidence = typeof args[1] === "number" ? args[1] : (ClassificationConfidenceBias.get(classification) ?? 1);
            match = {
                classification,
                confidence,
            };
        }
        else {
            match = {
                ...args[0],
                confidence: args[0].confidence ?? ClassificationConfidenceBias.get(args[0].classification) ?? 1,
            };
        }
        if (!match.classification) {
            throw new TypeError("Classification must be a non-empty string");
        }
        if (typeof match.confidence !== "number") {
            throw new TypeError("Confidence must be a number");
        }
        if (match.confidence < 0) {
            throw new RangeError(`${match.classification}: Confidence must be greater than or equal to 0: ${match.confidence}`);
        }
        if (match.confidence > 1) {
            throw new RangeError(`${match.classification}: Confidence must be less than or equal to 1: ${match.confidence}`);
        }
        const existing = this.get(match.classification);
        // Ensure that duplicate classifications do not reduce confidence
        if (existing && existing.confidence >= match.confidence) {
            return;
        }
        this.set(match.classification, match);
    }
    /**
     * Predicate to determine if the map contains a classification that is visible.
     */
    hasVisibleClassification(classification) {
        return classification ? this.has(classification) : Iterator.from(this.keys()).some(isVisibleClassification);
    }
    /**
     * Serialize the classification map to JSON.
     */
    toJSON() {
        return this.values().toArray();
    }
    static from(...input) {
        const map = new ClassificationsMatchMap();
        for (const entry of input) {
            map.add(entry);
        }
        return map;
    }
}
//# sourceMappingURL=Classification.js.map