/**
 * Copyright (c) 2020-present, Goldman Sachs
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import { ActionState } from '@finos/legend-shared';
import * as monaco from 'monaco-editor';
import { CODE_EDITOR_LANGUAGE, moveCursorToPosition, } from '@finos/legend-code-editor';
import { action, makeObservable, observable } from 'mobx';
export class SqlExecutionResult {
}
export class CsvSqlExecutionResult extends SqlExecutionResult {
    value;
    sqlDuration;
    constructor(value, sqlDuration) {
        super();
        this.value = value;
        this.sqlDuration = sqlDuration;
    }
}
export class QueryExecutionResult extends SqlExecutionResult {
    result;
    constructor(result) {
        super();
        this.result = result;
    }
}
const SQL_KEYWORDS = [
    'AND',
    'AS',
    'ASC',
    'BETWEEN',
    'DESC',
    'DISTINCT',
    'EXEC',
    'EXISTS',
    'FROM',
    'FULL OUTER JOIN',
    'GROUP BY',
    'HAVING',
    'IN',
    'INNER JOIN',
    'IS NULL',
    'IS NOT NULL',
    'JOIN',
    'LEFT JOIN',
    'LIKE',
    'LIMIT',
    'NOT',
    'NOT NULL',
    'OR',
    'ORDER BY',
    'OUTER JOIN',
    'RIGHT JOIN',
    'SELECT',
    'SELECT DISTINCT',
    'SELECT INTO',
    'SELECT TOP',
    'TOP',
    'UNION',
    'UNION ALL',
    'UNIQUE',
    'WHERE',
];
export class AbstractSQLPlaygroundState {
    theme;
    sqlText = '';
    executeRawSQLState;
    sqlExecutionResult;
    sqlEditorViewState;
    sqlEditorTextModel;
    sqlEditor;
    isLocalModeEnabled;
    constructor() {
        this.sqlEditorTextModel = monaco.editor.createModel(this.sqlText, CODE_EDITOR_LANGUAGE.SQL);
        this.isLocalModeEnabled = false;
        this.executeRawSQLState = ActionState.create();
        this.theme = 'light';
        makeObservable(this, {
            sqlExecutionResult: observable,
            isLocalModeEnabled: observable,
            sqlText: observable,
            executeRawSQLState: observable,
            stopExecuteSQL: action,
            setSQLEditor: action,
            setSQLEditorViewState: action,
            setSQLText: action,
            setTheme: action,
            toggleIsLocalModeEnabled: action,
            sqlEditorViewState: observable.ref,
            sqlEditor: observable.ref,
        });
    }
    getCodeCompletionSuggestions() {
        return SQL_KEYWORDS;
    }
    stopExecuteSQL() {
        this.sqlExecutionResult = undefined;
    }
    setSqlExecutionResult(val) {
        this.sqlExecutionResult = val;
    }
    setSQLText(val) {
        this.sqlText = val;
    }
    setTheme(val) {
        this.theme = val;
    }
    setSQLEditorViewState(state) {
        this.sqlEditorViewState = state;
    }
    setSQLEditor(val) {
        this.sqlEditor = val;
        if (val) {
            const lastLine = this.sqlEditorTextModel.getLineCount();
            moveCursorToPosition(val, {
                lineNumber: lastLine,
                column: this.sqlEditorTextModel.getLineMaxColumn(lastLine),
            });
        }
    }
    toggleIsLocalModeEnabled() {
        this.isLocalModeEnabled = !this.isLocalModeEnabled;
        this.sqlExecutionResult = undefined;
    }
    get isExecuting() {
        return this.executeRawSQLState.isInProgress;
    }
    get hasResult() {
        return this.sqlExecutionResult !== undefined;
    }
}
//# sourceMappingURL=AbstractSQLPlaygroundState.js.map