import { colCache } from "./utils/col-cache.js";
class DataValidations {
    constructor(model) {
        this.model = model || {};
    }
    add(address, validation) {
        return (this.model[address] = validation);
    }
    find(address) {
        // First check direct address match
        const direct = this.model[address];
        if (direct !== undefined) {
            return direct;
        }
        // Check range: prefixed keys in model (from parsing ranges)
        // Only decode address if we see at least one range key.
        let decoded;
        for (const key in this.model) {
            if (!key.startsWith("range:")) {
                continue;
            }
            decoded || (decoded = colCache.decodeAddress(address));
            const rangeStr = key.slice(6); // Remove "range:" prefix
            const rangeDecoded = colCache.decodeEx(rangeStr);
            if (!rangeDecoded.dimensions) {
                continue;
            }
            const tl = rangeDecoded.tl;
            const br = rangeDecoded.br;
            if (decoded.row >= tl.row &&
                decoded.row <= br.row &&
                decoded.col >= tl.col &&
                decoded.col <= br.col) {
                return this.model[key];
            }
        }
        return undefined;
    }
    remove(address) {
        this.model[address] = undefined;
    }
}
export { DataValidations };
