/*
 * Copyright 2026, Jaime Terrats.
 *
 * 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 { basename } from 'node:path';
export const flowParser = {
    type: 'Flow',
    glob: '**/flows/*.flow-meta.xml',
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    parse(filePath, _content) {
        const name = basename(filePath, '.flow-meta.xml');
        if (!name)
            return null;
        return {
            apiName: name,
            type: 'Flow',
            path: filePath,
            category: 'flow',
            dependencies: [],
        };
    },
    extractDependencies(_entry, content) {
        const deps = new Set();
        // Object references: <object>ObjectName</object>
        const objectPattern = /<object>([A-Za-z][A-Za-z0-9_]+)<\/object>/g;
        let match = objectPattern.exec(content);
        while (match) {
            deps.add(match[1]);
            match = objectPattern.exec(content);
        }
        // Apex action invocations: <actionName>ClassName</actionName>
        const actionPattern = /<actionName>([A-Za-z][A-Za-z0-9_]+)<\/actionName>/g;
        match = actionPattern.exec(content);
        while (match) {
            deps.add(match[1]);
            match = actionPattern.exec(content);
        }
        // Subflow references: <flowName>FlowApiName</flowName>
        const subflowPattern = /<flowName>([A-Za-z][A-Za-z0-9_]+)<\/flowName>/g;
        match = subflowPattern.exec(content);
        while (match) {
            deps.add(match[1]);
            match = subflowPattern.exec(content);
        }
        return [...deps];
    },
};
//# sourceMappingURL=flow-parser.js.map