/*
 * 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 permParser = {
    type: 'PermissionSet',
    glob: '**/permissionsets/*.permissionset-meta.xml',
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    parse(filePath, _content) {
        const name = basename(filePath, '.permissionset-meta.xml');
        if (!name)
            return null;
        return {
            apiName: name,
            type: 'PermissionSet',
            path: filePath,
            category: 'permissionset',
            dependencies: [],
        };
    },
    extractDependencies(_entry, content) {
        const deps = new Set();
        // Object permissions: <object>ObjectName</object> within objectPermissions
        const objectPermPattern = /<objectPermissions>[\s\S]*?<object>([A-Za-z][A-Za-z0-9_]+)<\/object>[\s\S]*?<\/objectPermissions>/g;
        let match = objectPermPattern.exec(content);
        while (match) {
            deps.add(match[1]);
            match = objectPermPattern.exec(content);
        }
        // Field permissions: <field>Object.Field</field>
        const fieldPermPattern = /<field>([A-Za-z][A-Za-z0-9_]+)\.[A-Za-z][A-Za-z0-9_]+<\/field>/g;
        match = fieldPermPattern.exec(content);
        while (match) {
            deps.add(match[1]);
            match = fieldPermPattern.exec(content);
        }
        // Class accesses: <apexClass>ClassName</apexClass>
        const classPattern = /<apexClass>([A-Za-z][A-Za-z0-9_]+)<\/apexClass>/g;
        match = classPattern.exec(content);
        while (match) {
            deps.add(match[1]);
            match = classPattern.exec(content);
        }
        return [...deps];
    },
};
//# sourceMappingURL=perm-parser.js.map