"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SchemaListener = exports.SchemaContextKindEnum = void 0;
const utils_1 = require("../utils");
var SchemaContextKindEnum;
(function (SchemaContextKindEnum) {
    SchemaContextKindEnum["VIEW"] = "view";
    SchemaContextKindEnum["CATALOG"] = "catalog";
    SchemaContextKindEnum["DATABASE"] = "database";
    SchemaContextKindEnum["TABLE"] = "table";
    SchemaContextKindEnum["COLUMN"] = "column";
})(SchemaContextKindEnum = exports.SchemaContextKindEnum || (exports.SchemaContextKindEnum = {}));
class SchemaListener {
    constructor() {
        this._schemaContexts = [];
    }
    getSchemaContexts() {
        return this._schemaContexts;
    }
    enterView(ctx) {
        this._schemaContexts.push({
            kind: SchemaContextKindEnum.VIEW,
            text: ctx.text,
            catalogName: ctx.database()?.catalog()?.catalogName()
                ? (0, utils_1.sanitizeText)(ctx.database().catalog().catalogName().text)
                : undefined,
            databaseName: ctx.database()?.databaseName() ? (0, utils_1.sanitizeText)(ctx.database().databaseName().text) : undefined,
            viewName: ctx.viewName().text,
            startOffset: ctx.start.startIndex,
            endOffset: ctx.start.startIndex + ctx.text.length
        });
    }
    enterCatalog(ctx) {
        this._schemaContexts.push({
            kind: SchemaContextKindEnum.CATALOG,
            text: ctx.text,
            catalogName: (0, utils_1.sanitizeText)(ctx.catalogName().text),
            startOffset: ctx.start.startIndex,
            endOffset: ctx.start.startIndex + ctx.text.length
        });
    }
    enterDatabase(ctx) {
        this._schemaContexts.push({
            kind: SchemaContextKindEnum.DATABASE,
            text: ctx.text,
            catalogName: ctx.catalog()?.catalogName() ? (0, utils_1.sanitizeText)(ctx.catalog().catalogName().text) : undefined,
            databaseName: (0, utils_1.sanitizeText)(ctx.databaseName().text),
            startOffset: ctx.start.startIndex,
            endOffset: ctx.start.startIndex + ctx.text.length
        });
    }
    enterTable(ctx) {
        this._schemaContexts.push({
            kind: SchemaContextKindEnum.TABLE,
            text: ctx.text,
            catalogName: ctx.database()?.catalog()?.catalogName()
                ? (0, utils_1.sanitizeText)(ctx.database().catalog().catalogName().text)
                : undefined,
            databaseName: ctx.database()?.databaseName() ? (0, utils_1.sanitizeText)(ctx.database().databaseName().text) : undefined,
            tableName: (0, utils_1.sanitizeText)(ctx.tableName().text),
            startOffset: ctx.start.startIndex,
            endOffset: ctx.start.startIndex + ctx.text.length
        });
    }
    enterDereference(ctx) {
        this._schemaContexts.push({
            kind: SchemaContextKindEnum.COLUMN,
            text: ctx.text,
            catalogName: ctx.table()?.database()?.catalog()?.catalogName()
                ? (0, utils_1.sanitizeText)(ctx.table().database().catalog().catalogName().text)
                : undefined,
            databaseName: ctx.table()?.database()?.databaseName()
                ? (0, utils_1.sanitizeText)(ctx.table().database().databaseName().text)
                : undefined,
            tableName: ctx.table()?.tableName() ? ctx.table().tableName().text : undefined,
            columnName: ctx.columnName() ? ctx.columnName().text : '',
            startOffset: ctx.start.startIndex,
            endOffset: ctx.start.startIndex + ctx.text.length
        });
    }
}
exports.SchemaListener = SchemaListener;
