"use strict";
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module Workspace
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.WorkspaceEditor = void 0;
const BlobContainerService_1 = require("../BlobContainerService");
const WorkspaceSqliteDb_1 = require("../internal/workspace/WorkspaceSqliteDb");
const WorkspaceImpl_1 = require("../internal/workspace/WorkspaceImpl");
const Symbols_1 = require("../internal/Symbols");
const IModelHost_1 = require("../IModelHost");
/** @beta */
var WorkspaceEditor;
(function (WorkspaceEditor) {
    /**
     * Create a new [[WorkspaceEditor]] for creating new versions of [[WorkspaceDb]]s.
     * @note the caller becomes the owner of the Workspace.Editor and is responsible for calling [[WorkspaceEditor.close]] on it when they are finished using it.
     * @note It is illegal to have more than one Workspace.Editor active in a single session.
     */
    function construct() {
        return (0, WorkspaceImpl_1.constructWorkspaceEditor)();
    }
    WorkspaceEditor.construct = construct;
    /**
     * Create a new, empty, [[EditableWorkspaceDb]] file on the local filesystem for importing [[Workspace]] resources.
     * @note Do not pass an untrusted or unintended path in `localFileName`.
     * This helper creates or overwrites the file at that location; callers that need fail-if-exists behavior should check first.
     */
    function createEmptyDb(args) {
        WorkspaceSqliteDb_1.WorkspaceSqliteDb.createNewDb(args.localFileName, args);
    }
    WorkspaceEditor.createEmptyDb = createEmptyDb;
    /**
     * Query the [[BlobContainer]] service for all workspace containers associated with a given iTwin.
     * This is a convenience wrapper around `BlobContainer.service.queryContainersMetadata` that
     * automatically filters by `containerType: "workspace"`.
     * @param args - The query arguments including the iTwinId.
     * @returns A promise that resolves to the matching container metadata entries.
     * @note Requires [[IModelHost.authorizationClient]] to be configured.
     */
    async function queryContainers(args) {
        if (undefined === BlobContainerService_1.BlobContainer.service)
            throw new Error("BlobContainer.service is not available. Ensure IModelHost is initialized with a valid configuration.");
        const userToken = await IModelHost_1.IModelHost.getAccessToken();
        return BlobContainerService_1.BlobContainer.service.queryContainersMetadata(userToken, { ...args, containerType: args.containerType ?? "workspace" });
    }
    WorkspaceEditor.queryContainers = queryContainers;
})(WorkspaceEditor || (exports.WorkspaceEditor = WorkspaceEditor = {}));
//# sourceMappingURL=WorkspaceEditor.js.map