"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CliStateProvider = void 0;
const MablscriptImporter_1 = __importDefault(require("../sharedUtils/mablscript/MablscriptImporter"));
class CliStateProvider {
    constructor(state, trainingContext, flowCache, accountFeatures, snippetCache, applicationEnterTextMode) {
        this.parsedFlowStepsCache = new Map();
        this.state = state;
        this.trainingContext = trainingContext;
        this.flowCache = flowCache;
        this.accountFeatures = accountFeatures;
        this.snippetCache = snippetCache;
        this.applicationEnterTextMode = applicationEnterTextMode;
    }
    getTestGenerationStatus() {
        return this.state.getStatus();
    }
    getActiveSession() {
        return this.state.getActiveSession();
    }
    getAgentState() {
        return this.state.getAgentState();
    }
    getPublicState() {
        return this.state.getPublicState();
    }
    getTestIntent() {
        return this.state.getTestIntent();
    }
    getConversations() {
        return this.state.getConversations();
    }
    getLastToolsExecuted() {
        return this.state.getLastToolsExecuted();
    }
    getActiveOrgId() {
        return this.state.getWorkspaceId();
    }
    getSteps() {
        return this.state.getSteps();
    }
    getNextStepIndex() {
        return this.state.getNextStepIndex();
    }
    getLastVisitUrl() {
        return this.state.getLastVisitUrl();
    }
    getVariables() {
        return this.state.getVariables();
    }
    getSnippetsByInvariantId() {
        return this.state.getSnippetsByInvariantId();
    }
    async getSnippet(snippetId) {
        const cached = this.state.getSnippetsByInvariantId()[snippetId];
        if (cached) {
            return cached;
        }
        if (!this.snippetCache) {
            return undefined;
        }
        const snippet = await this.snippetCache.getSnippet(snippetId);
        if (snippet) {
            this.state.setSnippet(snippetId, snippet);
        }
        return snippet;
    }
    async getFlow(invariantId) {
        return this.flowCache.getFlow(invariantId);
    }
    getImportedFlowSteps(flowId) {
        const cached = this.parsedFlowStepsCache.get(flowId);
        if (cached) {
            return cached;
        }
        const cachedFlows = this.flowCache.getCachedFlows();
        const flow = cachedFlows[flowId];
        if (!flow) {
            return [];
        }
        const steps = [];
        const importer = new MablscriptImporter_1.default({ steps: [], flowSelectors: this.state.getElementSelectors() }, this.state.getVariables(), this.state.getSnippetsByInvariantId());
        importer.importFlow(flow, steps);
        this.parsedFlowStepsCache.set(flowId, steps);
        return steps;
    }
    getFlowCache() {
        return this.flowCache;
    }
    isReplayRunning() {
        return this.state.isReplayRunning();
    }
    getReplayResponse() {
        return this.state.getReplayResponse();
    }
    getLastFlowFailure() {
        return this.state.getLastFlowFailure();
    }
    getTrainingAction() {
        return this.state.getTrainingAction();
    }
    getTrainingSessionId() {
        return this.state.getTrainingSessionId();
    }
    getActiveContextInfo() {
        const tabId = this.trainingContext.getActiveTab();
        const frameId = this.trainingContext.getCurrentFrame();
        return Promise.resolve({ tabId, frameId });
    }
    async waitForReplayCompletion() {
        while (this.state.isReplayRunning()) {
            await new Promise((resolve) => setTimeout(resolve, 100));
        }
    }
    getElementSelectors() {
        return this.state.getElementSelectors();
    }
    isCapturingHovers() {
        return this.state.isCapturingHovers();
    }
    getTrainingContext() {
        return this.trainingContext;
    }
    getAuthoringSessionId() {
        return this.state.getAuthoringSessionId();
    }
    setAuthoringSessionId(sessionId) {
        this.state.setAuthoringSessionId(sessionId);
    }
    getAuthoringMessages() {
        return this.state.getAuthoringMessages();
    }
    addAuthoringMessages(messages) {
        this.state.addAuthoringMessages(messages);
    }
    clearAuthoringMessages() {
        this.state.clearAuthoringMessages();
    }
    getLastSentMessageCount() {
        return this.state.getLastSentMessageCount();
    }
    setLastSentMessageCount(count) {
        this.state.setLastSentMessageCount(count);
    }
    getArtifacts() {
        return this.state.getArtifacts();
    }
    setArtifact(name, artifact) {
        this.state.setArtifact(name, artifact);
    }
    getArtifact(name) {
        return this.state.getArtifact(name);
    }
    clearArtifacts() {
        this.state.clearArtifacts();
    }
    hasStepGroupsFeature() {
        return this.accountFeatures?.hasStepGroups() ?? false;
    }
    getApplicationEnterTextMode() {
        return this.applicationEnterTextMode;
    }
}
exports.CliStateProvider = CliStateProvider;
