"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ProjectInfoUtilities_1 = require("../ProjectInfoUtilities");
const TestDefinition_1 = require("../tests/TestDefinition");
const MaxOrphanFileResults = 5;
var CheckIntegrityTest;
(function (CheckIntegrityTest) {
    CheckIntegrityTest["OrphanedFile"] = "OrphanedFile";
    CheckIntegrityTest["UnexpectedManifest"] = "UnexpectedManifest";
})(CheckIntegrityTest || (CheckIntegrityTest = {}));
const CheckIntegrityTests = {
    OrphanedFile: {
        id: 101,
        title: "Extraneous Files Or Folder",
        defaultMessage: "Project contains extraneous file or folder",
    },
    UnexpectedManifest: {
        id: 102,
        title: "Unexpected Manifest Structure",
        defaultMessage: "Pack has an unexpected structure, multiple manifests detected. Nested manifests are not allowed.",
    },
};
class CheckProjectIntegrityGenerator {
    id = "PRJINT";
    title = "Check Project Integrity Generator";
    canAlwaysProcess = true;
    generate(project) {
        const orphanResults = this.checkOrphanedFiles(project);
        const manifestResults = this.checkNestedManifests(project);
        const results = [...orphanResults, ...manifestResults];
        return Promise.resolve(results);
    }
    checkOrphanedFiles(project) {
        //limit items to avoid spam, then get results
        const results = project.unknownFiles
            .slice(0, MaxOrphanFileResults)
            .map((file) => (0, TestDefinition_1.resultFromTest)(CheckIntegrityTests.OrphanedFile, { id: this.id, data: file.extendedPath }));
        return results;
    }
    checkNestedManifests(project) {
        const results = project.packs
            // get all manifests within each pack
            .map((pack) => [pack, pack.getPackItems().filter((item) => item.name === "manifest.json")])
            // more than one manifest indicates an issue
            .filter(([_pack, manifests]) => manifests.length > 1)
            // get results
            .map(([pack]) => (0, TestDefinition_1.resultFromTest)(CheckIntegrityTests.UnexpectedManifest, { id: this.id, data: pack.name }));
        return results;
    }
    getTopicData(topicId) {
        const title = ProjectInfoUtilities_1.default.getGeneralTopicTitle(topicId) || (0, TestDefinition_1.getTestTitleById)(CheckIntegrityTests, topicId);
        return { title };
    }
    summarize() { }
}
exports.default = CheckProjectIntegrityGenerator;

//# sourceMappingURL=../../maps/info/projectGenerators/CheckProjectIntegrityGenerator.js.map
