/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import { DbResult, Logger } from "@itwin/core-bentley";
import { Element } from "../Element";
export function fmtElement(iModel, elementId) {
    const el = iModel.elements.getElement(elementId);
    return `${el.id} ${el.classFullName} ${el.getDisplayLabel()}`;
}
export function fmtModel(model) {
    return `${model.id} ${model.classFullName} ${model.name}`;
}
export function printElementTree(loggerCategory, seen, iModel, elementId, indent) {
    if (seen.has(elementId)) {
        Logger.logTrace(loggerCategory, `${"\t".repeat(indent)}${fmtElement(iModel, elementId)} (SEEN)`);
        return;
    }
    seen.add(elementId);
    Logger.logTrace(loggerCategory, `${"\t".repeat(indent)}${fmtElement(iModel, elementId)}`);
    for (const child of iModel.elements.queryChildren(elementId)) {
        printElementTree(loggerCategory, seen, iModel, child, indent + 1);
    }
    const subModel = iModel.models.tryGetModel(elementId);
    if (subModel !== undefined) {
        Logger.logTrace(loggerCategory, `${"\t".repeat(indent)} subModel ${fmtModel(subModel)}:`);
        // eslint-disable-next-line @typescript-eslint/no-deprecated
        iModel.withPreparedStatement(`select ecinstanceid from ${Element.classFullName} where Model.Id = ?`, (stmt) => {
            stmt.bindId(1, subModel.id);
            while (stmt.step() === DbResult.BE_SQLITE_ROW) {
                printElementTree(loggerCategory, seen, iModel, stmt.getValue(0).getId(), indent + 1);
            }
        });
    }
}
//# sourceMappingURL=PrintElementTree.js.map