"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseScopes = exports.normalizeScopeName = exports.parseScope = void 0;
const tslib_1 = require("tslib");
const camelCase_1 = tslib_1.__importDefault(require("lodash/camelCase"));
const upperFirst_1 = tslib_1.__importDefault(require("lodash/upperFirst"));
const scopes_1 = require("./scopes");
const parseScope = (scope) => {
    const [action, predicate] = scope.split(':');
    const [subjectPart, modifier] = predicate.split('@');
    const subject = (0, upperFirst_1.default)((0, camelCase_1.default)(subjectPart));
    return [
        action,
        subject,
        modifier,
    ];
};
exports.parseScope = parseScope;
const normalizeScopeName = (scope) => {
    const [action, subject, modifier] = (0, exports.parseScope)(scope);
    return `${action}:${subject}${modifier ? `@${modifier}` : ''}`;
};
exports.normalizeScopeName = normalizeScopeName;
const parseScopes = ({ scopes, isEnterprise, }) => {
    const scopeMap = (0, scopes_1.getAllScopeMap)({ isEnterprise });
    const filtered = scopes.map(exports.normalizeScopeName).filter((scope) => {
        const foundScope = scopeMap[scope];
        if (!foundScope) {
            // eslint-disable-next-line no-console
            console.warn(`Invalid scope: ${scope}. Please check the scope name and try again.`);
            return false;
        }
        return true;
    });
    return new Set(filtered);
};
exports.parseScopes = parseScopes;
//# sourceMappingURL=parseScopes.js.map