"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.solve = void 0;
const areDigraphsValid_1 = require("./areDigraphsValid");
const fillPattern_1 = require("./fillPattern");
const generatePatterns_1 = require("./generatePatterns");
const getPatternScore_1 = require("./getPatternScore");
const getUniquePatterns_1 = require("./getUniquePatterns");
const solve = (trie, config, board, tiles) => {
    const patterns = (0, generatePatterns_1.generatePatterns)(config, board);
    const filledPatterns = patterns.flatMap((pattern) => (0, fillPattern_1.fillPattern)(trie, config, pattern, tiles));
    const validPatterns = config.twoCharacterTiles.length > 0
        ? filledPatterns.filter((pattern) => (0, areDigraphsValid_1.areDigraphsValid)(config, pattern))
        : filledPatterns;
    const uniquePatterns = (0, getUniquePatterns_1.getUniquePatterns)(validPatterns);
    const results = uniquePatterns.map((pattern, index) => ({
        cells: pattern.cells.map((cell) => cell.toJson()),
        collisions: pattern.getCollisions().map((collision) => collision.cells.map((cell) => cell.toJson())),
        id: index,
        points: (0, getPatternScore_1.getPatternScore)(config, pattern),
    }));
    return results;
};
exports.solve = solve;
