"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
const ste_events_1 = require("ste-events");
class StorageBase {
    isContentUpdated = false;
    readOnly = false;
    static slashFolderDelimiter = "/";
    get folderDelimiter() {
        return StorageBase.slashFolderDelimiter;
    }
    #onFileAdded = new ste_events_1.EventDispatcher();
    #onFileRemoved = new ste_events_1.EventDispatcher();
    #onFileContentsUpdated = new ste_events_1.EventDispatcher();
    #onFolderMoved = new ste_events_1.EventDispatcher();
    #storagePath;
    errorStatus;
    errorMessage;
    channelId;
    get storagePath() {
        return this.#storagePath;
    }
    set storagePath(newStoragePath) {
        this.#storagePath = newStoragePath;
    }
    resetContentUpdated() {
        this.isContentUpdated = false;
    }
    get onFileAdded() {
        return this.#onFileAdded.asEvent();
    }
    get onFileRemoved() {
        return this.#onFileRemoved.asEvent();
    }
    get onFileContentsUpdated() {
        return this.#onFileContentsUpdated.asEvent();
    }
    get onFolderMoved() {
        return this.#onFolderMoved.asEvent();
    }
    async ensureFolderFromStorageRelativePath(path) {
        if (path.startsWith("/" + this.rootFolder.name + "/")) {
            path = path.substring(this.rootFolder.name.length + 1);
        }
        return this.rootFolder.ensureFolderFromRelativePath(path);
    }
    notifyFileAdded(file) {
        this.#onFileAdded.dispatch(this, file);
    }
    notifyFileContentsUpdated(file) {
        this.isContentUpdated = true;
        this.#onFileContentsUpdated.dispatch(this, file);
    }
    notifyFolderMoved(folderMove) {
        this.isContentUpdated = true;
        this.#onFolderMoved.dispatch(this, folderMove);
    }
    notifyFileRemoved(fileName) {
        this.#onFileRemoved.dispatch(this, fileName);
    }
    joinPath(pathA, pathB) {
        let fullPath = pathA;
        if (!fullPath.endsWith(StorageBase.slashFolderDelimiter)) {
            fullPath += StorageBase.slashFolderDelimiter;
        }
        fullPath += pathB;
        return fullPath;
    }
    static getParentFolderPath(path) {
        const lastDelim = path.lastIndexOf(StorageBase.slashFolderDelimiter);
        if (lastDelim < 0) {
            return path;
        }
        return path.substring(0, lastDelim);
    }
}
exports.default = StorageBase;

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