import * as fs from "fs";
import * as path from "path";
import RuleRepositoryJSON from "./_infra/RuleRepositoryJSON";
import TraceRepositoryJSON from "./_infra/TraceRepositoryJSON";
import ReplayerApplication from "./application/replayerApplication";
import Word from "./domain/word";

const rulesRepository = new RuleRepositoryJSON(path.join(__dirname, "..", "rules"));
const traceRepository = new TraceRepositoryJSON();

const replayer = new ReplayerApplication(rulesRepository, traceRepository);

const executedTracePath = path.join(__dirname, "..", "output", "test.json");

replayer.playTraceSet("cdiscount-crowd.json", "cdiscount", "https://cdiscount.com")
    .then((executedTraces: Word[][]) => {
        const filteredTraces = executedTraces.map((trace) => trace.map((word) => word.toString()));
        fs.writeFileSync(executedTracePath, JSON.stringify(filteredTraces, null, 2));
        return;
    });
