import Z3Module from './z3Module.js';
import { instance as letterInstance, } from '../../../symbols/letterSymbol.js';
import { Point } from 'grilops';
export default class LetterModule extends Z3Module {
    constructor() {
        super(...arguments);
        Object.defineProperty(this, "id", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: letterInstance.id
        });
    }
    encode(grid, ctx) {
        const symbols = grid.symbols.get(this.id);
        if (!symbols || symbols.length === 0) {
            return;
        }
        const rc = ctx.regionConstrainer;
        const letterMap = new Map();
        for (const symbol of symbols) {
            const x = Math.floor(symbol.x);
            const y = Math.floor(symbol.y);
            if (letterMap.has(symbol.letter)) {
                ctx.solver.add(letterMap
                    .get(symbol.letter)
                    .eq(rc.regionIdGrid.get(new Point(y, x))));
            }
            else {
                letterMap.set(symbol.letter, rc.regionIdGrid.get(new Point(y, x)));
            }
        }
        const letters = Array.from(letterMap.values());
        for (let i = 0; i < letters.length - 1; i++) {
            for (let j = i + 1; j < letters.length; j++) {
                ctx.solver.add(letters[i].neq(letters[j]));
            }
        }
    }
}
export const instance = new LetterModule();
