import { BaseIndexer } from './base-indexer.js';
export class KotlinIndexer extends BaseIndexer {
    constructor() {
        super(...arguments);
        this.language = 'kotlin';
    }
    extractExports(root, filePath) {
        const exports = [];
        const addExport = (name, type, node) => {
            exports.push({
                name,
                type,
                filePath,
                line: node.startPosition.row + 1,
                column: node.startPosition.column + 1,
                parameters: this.extractParameters(node)
            });
        };
        // 1. Classes/Objects
        const classNodes = root.descendantsOfType('class_declaration');
        const objectNodes = root.descendantsOfType('object_declaration');
        for (const node of [...classNodes, ...objectNodes]) {
            const nameNode = node.childForFieldName('identifier');
            if (nameNode)
                addExport(nameNode.text, 'class', node);
        }
        // 2. Functions
        const funcNodes = root.descendantsOfType('function_declaration');
        for (const node of funcNodes) {
            const nameNode = node.childForFieldName('identifier');
            if (nameNode)
                addExport(nameNode.text, 'function', node);
        }
        return exports;
    }
    extractImports(root) {
        const imports = {};
        // import pak.age.Class
        const importNodes = root.descendantsOfType('import_header');
        for (const node of importNodes) {
            const identifierNode = node.children.find(c => c.type === 'identifier' || c.type === 'navigation_expression');
            if (identifierNode) {
                const fullPath = identifierNode.text;
                const parts = fullPath.split('.');
                const localName = parts[parts.length - 1];
                if (localName)
                    imports[localName] = fullPath;
            }
        }
        return imports;
    }
    extractCalls(root) {
        const calls = [];
        const callNodes = root.descendantsOfType('call_expression');
        for (const node of callNodes) {
            const nameNode = node.childForFieldName('navigation_suffix')?.childForFieldName('simple_identifier') ||
                node.childForFieldName('simple_identifier');
            if (nameNode) {
                const name = nameNode.text;
                const argsNode = node.childForFieldName('value_arguments');
                const argPositions = [];
                if (argsNode) {
                    for (let i = 0; i < argsNode.childCount; i++) {
                        const arg = argsNode.child(i);
                        if (arg && arg.isNamed && arg.text !== '(' && arg.text !== ')') {
                            argPositions.push({
                                row: arg.startPosition.row,
                                column: arg.startPosition.column
                            });
                        }
                    }
                }
                calls.push({ name, argPositions });
            }
        }
        return calls;
    }
    extractParameters(node) {
        const params = [];
        const paramNode = node.childForFieldName('function_value_parameters');
        if (paramNode) {
            const pNodes = paramNode.descendantsOfType('function_value_parameter');
            for (const p of pNodes) {
                const nameNode = p.childForFieldName('simple_identifier');
                if (nameNode)
                    params.push(nameNode.text);
            }
        }
        return params;
    }
}
//# sourceMappingURL=kotlin-indexer.js.map