"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
const IFileDifference_1 = require("./IFileDifference");
const IFolderDifference_1 = require("./IFolderDifference");
const StorageUtilities_1 = require("./StorageUtilities");
const ZipStorage_1 = require("./ZipStorage");
class DifferenceSet {
    fileDifferences = [];
    folderDifferences = [];
    async getZip() {
        const zipStorage = new ZipStorage_1.default();
        for (let i = 0; i < this.fileDifferences.length; i++) {
            const fileDiff = this.fileDifferences[i];
            if (fileDiff.type === IFileDifference_1.FileDifferenceType.fileAdded || fileDiff.type === IFileDifference_1.FileDifferenceType.contentsDifferent) {
                if (fileDiff.updated) {
                    const zipFile = await zipStorage.rootFolder.ensureFileFromRelativePath(fileDiff.path);
                    if (fileDiff.updated.content) {
                        zipFile.setContent(fileDiff.updated.content);
                    }
                }
            }
        }
        await zipStorage.rootFolder.saveAll();
        return zipStorage;
    }
    getHasDeletions() {
        for (let i = 0; i < this.fileDifferences.length; i++) {
            if (this.fileDifferences[i].type === IFileDifference_1.FileDifferenceType.fileDeleted) {
                return true;
            }
        }
        for (let i = 0; i < this.folderDifferences.length; i++) {
            if (this.folderDifferences[i].type === IFolderDifference_1.FolderDifferenceType.folderDeleted) {
                return true;
            }
        }
        return false;
    }
    hasFileOnlyOfExtension(...extensions) {
        for (let i = 0; i < this.fileDifferences.length; i++) {
            const extension = StorageUtilities_1.default.getTypeFromName(this.fileDifferences[i].path);
            if (!extensions.includes(extension)) {
                return false;
            }
        }
        return true;
    }
    hasFileOfExtension(...extensions) {
        for (let i = 0; i < this.fileDifferences.length; i++) {
            const extension = StorageUtilities_1.default.getTypeFromName(this.fileDifferences[i].path);
            if (extensions.includes(extension)) {
                return true;
            }
        }
        return false;
    }
    async copyFileUpdatesAndAdds(storage) {
        for (let i = 0; i < this.fileDifferences.length; i++) {
            const fileDiff = this.fileDifferences[i];
            if ((fileDiff.type === IFileDifference_1.FileDifferenceType.fileAdded || fileDiff.type === IFileDifference_1.FileDifferenceType.contentsDifferent) &&
                fileDiff.updated &&
                fileDiff.updated.content !== null) {
                const file = await storage.rootFolder.ensureFileFromRelativePath(fileDiff.path);
                file.setContent(fileDiff.updated.content);
            }
        }
    }
}
exports.default = DifferenceSet;

//# sourceMappingURL=../maps/storage/DifferenceSet.js.map
