"use strict";
var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
            ar[i] = from[i];
        }
    }
    return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AI_ASSISTANT_CORE_HEURISTICS = void 0;
function normalizeTerm(value) {
    return String(value || '')
        .trim()
        .toLowerCase()
        .replace(/\s+/g, ' ');
}
function uniqueStrings(values) {
    var seen = new Set();
    var unique = [];
    (values || []).forEach(function (value) {
        var normalized = normalizeTerm(value);
        if (!normalized || seen.has(normalized)) {
            return;
        }
        seen.add(normalized);
        unique.push(normalized);
    });
    return unique;
}
function uniqueCollections(values) {
    var seen = new Set();
    var unique = [];
    (values || []).forEach(function (value) {
        var normalized = normalizeTerm(value).replace(/[^a-z0-9._-]/g, '');
        if (!normalized || seen.has(normalized)) {
            return;
        }
        seen.add(normalized);
        unique.push(normalized);
    });
    return unique;
}
function mergeCollectionLists() {
    var groups = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        groups[_i] = arguments[_i];
    }
    return uniqueCollections((groups || []).reduce(function (acc, group) { return acc.concat(Array.isArray(group) ? group : []); }, []));
}
function singularizeToken(token) {
    var normalized = normalizeTerm(token);
    if (!normalized) {
        return '';
    }
    if (normalized.endsWith('ies') && normalized.length > 4) {
        return "".concat(normalized.slice(0, -3), "y");
    }
    if (normalized.length > 4
        && normalized.endsWith('s')
        && !normalized.endsWith('ss')
        && !normalized.endsWith('us')
        && !normalized.endsWith('is')) {
        return normalized.slice(0, -1);
    }
    return normalized;
}
function buildCollectionNameTerms(collection) {
    var normalized = normalizeTerm(collection).replace(/[^a-z0-9._-]/g, '');
    if (!normalized) {
        return [];
    }
    var withoutReportPrefix = normalized.startsWith('report-')
        ? normalized.slice('report-'.length)
        : normalized;
    var tokens = withoutReportPrefix.split(/[-_.]+/g).filter(Boolean);
    var singularTokens = tokens.map(singularizeToken).filter(Boolean);
    return uniqueStrings([
        normalized,
        withoutReportPrefix,
        withoutReportPrefix.replace(/[-_.]+/g, ' '),
        withoutReportPrefix.replace(/[-_.]+/g, ''),
        singularTokens.join('-'),
        singularTokens.join(' '),
        singularTokens.join('')
    ]);
}
function buildCollectionTermHintsFromCandidates(collections) {
    return uniqueCollections(collections).map(function (collection) { return ({
        terms: buildCollectionNameTerms(collection),
        collections: [collection]
    }); });
}
var REPORT_COLLECTION_HINT_CANDIDATES = uniqueCollections([
    'reports',
    'report-templates',
    'report-layouts',
    'report-builder-configs',
    'report-builder-layouts',
    'report-dashboards',
    'report-widgets',
    'report-favorites',
    'report-schedules',
    'report-runs',
    'saved-reports',
    'qb-reports',
    'dashboard-configs',
    'dashboard-widgets'
]);
var AUTH_COLLECTION_HINT_CANDIDATES = uniqueCollections([
    'users',
    'client-users',
    'billing-logged-in-users',
    'customer-auth-accounts',
    'customer-auth-sessions',
    'customer-portal-accounts',
    'customer-portal-sessions',
    'customer-portal-invites',
    'owners'
]);
var PERMISSION_NAV_COLLECTION_HINT_CANDIDATES = uniqueCollections([
    'roles',
    'permissions',
    'role-permissions',
    'user-groups',
    'dashboard-configs',
    'homepage-configs',
    'homepage-sections'
]);
var UI_WIDGET_COLLECTION_HINT_CANDIDATES = uniqueCollections([
    'dashboard-widgets',
    'report-widgets',
    'report-layouts',
    'report-templates',
    'dashboard-configs',
    'homepage-configs',
    'homepage-sections',
    'homepage-announcements',
    'ai-assist-configs',
    'systems'
]);
var SYSTEM_COLLECTION_HINT_CANDIDATES = uniqueCollections([
    'systems',
    'settings',
    'configs',
    'company-secrets',
    'ai-coder-apps',
    'ai-development-jobs',
    'build-instance-logs',
    'error-autofix-logs',
    'slow-query-logs',
    'work-logs',
    'crm-usage-logs',
    'mongo-performance-metrics',
    'mongo-snapshots',
    'aws-heartbeats',
    'aws-app-versions'
]);
var TABLE_COLLECTION_HINT_CANDIDATES = mergeCollectionLists(REPORT_COLLECTION_HINT_CANDIDATES, UI_WIDGET_COLLECTION_HINT_CANDIDATES);
var NAV_COLLECTION_HINT_CANDIDATES = mergeCollectionLists(PERMISSION_NAV_COLLECTION_HINT_CANDIDATES, UI_WIDGET_COLLECTION_HINT_CANDIDATES, ['modules', 'menus', 'navigation-items']);
var USER_PERMISSION_COLLECTION_HINT_CANDIDATES = mergeCollectionLists(['users', 'client-users', 'billing-logged-in-users'], AUTH_COLLECTION_HINT_CANDIDATES, PERMISSION_NAV_COLLECTION_HINT_CANDIDATES);
var AI_ASSISTANT_CORE_COLLECTION_ALIAS_OPTIONS = {
    report: REPORT_COLLECTION_HINT_CANDIDATES,
    reports: REPORT_COLLECTION_HINT_CANDIDATES,
    reporting: REPORT_COLLECTION_HINT_CANDIDATES,
    reportbuilder: REPORT_COLLECTION_HINT_CANDIDATES,
    reportbuilders: REPORT_COLLECTION_HINT_CANDIDATES,
    reportdesigner: REPORT_COLLECTION_HINT_CANDIDATES,
    reportdesigners: REPORT_COLLECTION_HINT_CANDIDATES,
    reportschema: REPORT_COLLECTION_HINT_CANDIDATES,
    reportschemas: REPORT_COLLECTION_HINT_CANDIDATES,
    dashboard: mergeCollectionLists(REPORT_COLLECTION_HINT_CANDIDATES, UI_WIDGET_COLLECTION_HINT_CANDIDATES),
    dashboards: mergeCollectionLists(REPORT_COLLECTION_HINT_CANDIDATES, UI_WIDGET_COLLECTION_HINT_CANDIDATES),
    analytics: REPORT_COLLECTION_HINT_CANDIDATES,
    kpi: REPORT_COLLECTION_HINT_CANDIDATES,
    kpis: REPORT_COLLECTION_HINT_CANDIDATES,
    chart: REPORT_COLLECTION_HINT_CANDIDATES,
    charts: REPORT_COLLECTION_HINT_CANDIDATES,
    graph: REPORT_COLLECTION_HINT_CANDIDATES,
    graphs: REPORT_COLLECTION_HINT_CANDIDATES,
    visualization: mergeCollectionLists(REPORT_COLLECTION_HINT_CANDIDATES, UI_WIDGET_COLLECTION_HINT_CANDIDATES),
    visualizations: mergeCollectionLists(REPORT_COLLECTION_HINT_CANDIDATES, UI_WIDGET_COLLECTION_HINT_CANDIDATES),
    widget: UI_WIDGET_COLLECTION_HINT_CANDIDATES,
    widgets: UI_WIDGET_COLLECTION_HINT_CANDIDATES,
    collapsetable: TABLE_COLLECTION_HINT_CANDIDATES,
    collapsetables: TABLE_COLLECTION_HINT_CANDIDATES,
    collapsibletable: TABLE_COLLECTION_HINT_CANDIDATES,
    collapsibletables: TABLE_COLLECTION_HINT_CANDIDATES,
    expandabletable: TABLE_COLLECTION_HINT_CANDIDATES,
    expandabletables: TABLE_COLLECTION_HINT_CANDIDATES,
    datatable: TABLE_COLLECTION_HINT_CANDIDATES,
    datatables: TABLE_COLLECTION_HINT_CANDIDATES,
    datagrid: TABLE_COLLECTION_HINT_CANDIDATES,
    datagrids: TABLE_COLLECTION_HINT_CANDIDATES,
    navbar: NAV_COLLECTION_HINT_CANDIDATES,
    navbars: NAV_COLLECTION_HINT_CANDIDATES,
    navbarmain: NAV_COLLECTION_HINT_CANDIDATES,
    navbarmodule: NAV_COLLECTION_HINT_CANDIDATES,
    navigation: NAV_COLLECTION_HINT_CANDIDATES,
    navigations: NAV_COLLECTION_HINT_CANDIDATES,
    sidebar: NAV_COLLECTION_HINT_CANDIDATES,
    sidebars: NAV_COLLECTION_HINT_CANDIDATES,
    menu: NAV_COLLECTION_HINT_CANDIDATES,
    menus: NAV_COLLECTION_HINT_CANDIDATES,
    modulemenu: NAV_COLLECTION_HINT_CANDIDATES,
    modulemenus: NAV_COLLECTION_HINT_CANDIDATES,
    login: AUTH_COLLECTION_HINT_CANDIDATES,
    logins: AUTH_COLLECTION_HINT_CANDIDATES,
    signin: AUTH_COLLECTION_HINT_CANDIDATES,
    signins: AUTH_COLLECTION_HINT_CANDIDATES,
    signinpage: AUTH_COLLECTION_HINT_CANDIDATES,
    authentication: AUTH_COLLECTION_HINT_CANDIDATES,
    auth: AUTH_COLLECTION_HINT_CANDIDATES,
    session: AUTH_COLLECTION_HINT_CANDIDATES,
    sessions: AUTH_COLLECTION_HINT_CANDIDATES,
    permission: USER_PERMISSION_COLLECTION_HINT_CANDIDATES,
    permissions: USER_PERMISSION_COLLECTION_HINT_CANDIDATES,
    role: USER_PERMISSION_COLLECTION_HINT_CANDIDATES,
    roles: USER_PERMISSION_COLLECTION_HINT_CANDIDATES,
    access: mergeCollectionLists(USER_PERMISSION_COLLECTION_HINT_CANDIDATES, AUTH_COLLECTION_HINT_CANDIDATES),
    authorization: mergeCollectionLists(USER_PERMISSION_COLLECTION_HINT_CANDIDATES, AUTH_COLLECTION_HINT_CANDIDATES),
    system: SYSTEM_COLLECTION_HINT_CANDIDATES,
    systems: SYSTEM_COLLECTION_HINT_CANDIDATES,
    setting: SYSTEM_COLLECTION_HINT_CANDIDATES,
    settings: SYSTEM_COLLECTION_HINT_CANDIDATES,
    config: SYSTEM_COLLECTION_HINT_CANDIDATES,
    configs: SYSTEM_COLLECTION_HINT_CANDIDATES,
    configuration: SYSTEM_COLLECTION_HINT_CANDIDATES,
    configurations: SYSTEM_COLLECTION_HINT_CANDIDATES,
    audit: SYSTEM_COLLECTION_HINT_CANDIDATES,
    audits: SYSTEM_COLLECTION_HINT_CANDIDATES,
    log: SYSTEM_COLLECTION_HINT_CANDIDATES,
    logs: SYSTEM_COLLECTION_HINT_CANDIDATES,
    notification: mergeCollectionLists(SYSTEM_COLLECTION_HINT_CANDIDATES, ['user-notifications']),
    notifications: mergeCollectionLists(SYSTEM_COLLECTION_HINT_CANDIDATES, ['user-notifications'])
};
var AI_ASSISTANT_CORE_COLLECTION_ALIASES = Object.keys(AI_ASSISTANT_CORE_COLLECTION_ALIAS_OPTIONS)
    .reduce(function (acc, key) {
    var options = AI_ASSISTANT_CORE_COLLECTION_ALIAS_OPTIONS[key] || [];
    var best = options[0];
    if (best) {
        acc[key] = best;
    }
    return acc;
}, {});
var AI_ASSISTANT_CORE_DOMAIN_TERM_HINTS = [
    {
        terms: [
            'report builder',
            'report builder schema',
            'report schema',
            'report designer',
            'build report',
            'custom report',
            'report filters',
            'report columns',
            'report query'
        ],
        collections: REPORT_COLLECTION_HINT_CANDIDATES
    },
    {
        terms: [
            'dashboard report',
            'dashboard widget',
            'analytics dashboard',
            'kpi dashboard',
            'chart dashboard'
        ],
        collections: mergeCollectionLists(REPORT_COLLECTION_HINT_CANDIDATES, UI_WIDGET_COLLECTION_HINT_CANDIDATES)
    },
    {
        terms: [
            'login issue',
            'cannot login',
            'log in failed',
            'sign in failed',
            'authentication issue',
            'session issue',
            'access denied'
        ],
        collections: mergeCollectionLists(AUTH_COLLECTION_HINT_CANDIDATES, PERMISSION_NAV_COLLECTION_HINT_CANDIDATES)
    },
    {
        terms: [
            'collapse table',
            'collapsible table',
            'expandable table',
            'collapse-table',
            'data table',
            'data-table',
            'datatable',
            'data grid',
            'table widget'
        ],
        collections: TABLE_COLLECTION_HINT_CANDIDATES
    },
    {
        terms: [
            'navbar main',
            'main navbar',
            'navbar module',
            'module navbar',
            'navigation bar',
            'main navigation',
            'module navigation',
            'sidebar navigation',
            'menu bar'
        ],
        collections: NAV_COLLECTION_HINT_CANDIDATES
    },
    {
        terms: [
            'system settings',
            'system config',
            'system configuration',
            'global settings',
            'platform settings',
            'admin settings',
            'audit log',
            'activity log'
        ],
        collections: SYSTEM_COLLECTION_HINT_CANDIDATES
    }
];
var AI_ASSISTANT_CORE_COLLECTION_HINT_CANDIDATES = uniqueCollections(mergeCollectionLists(REPORT_COLLECTION_HINT_CANDIDATES, AUTH_COLLECTION_HINT_CANDIDATES, PERMISSION_NAV_COLLECTION_HINT_CANDIDATES, UI_WIDGET_COLLECTION_HINT_CANDIDATES, SYSTEM_COLLECTION_HINT_CANDIDATES, TABLE_COLLECTION_HINT_CANDIDATES, NAV_COLLECTION_HINT_CANDIDATES, Object.values(AI_ASSISTANT_CORE_COLLECTION_ALIAS_OPTIONS)
    .reduce(function (acc, group) { return acc.concat(group || []); }, [])));
var AI_ASSISTANT_CORE_COLLECTION_TERM_HINTS = buildCollectionTermHintsFromCandidates(AI_ASSISTANT_CORE_COLLECTION_HINT_CANDIDATES);
var AI_ASSISTANT_CORE_TERM_HINTS = __spreadArray(__spreadArray([], __read(AI_ASSISTANT_CORE_DOMAIN_TERM_HINTS), false), __read(AI_ASSISTANT_CORE_COLLECTION_TERM_HINTS), false).map(function (entry) { return ({
    terms: uniqueStrings(entry.terms || []),
    collections: uniqueCollections(entry.collections || [])
}); }).filter(function (entry) { return entry.terms.length && entry.collections.length; });
exports.AI_ASSISTANT_CORE_HEURISTICS = Object.freeze({
    version: 3,
    collection_aliases: AI_ASSISTANT_CORE_COLLECTION_ALIASES,
    collection_alias_options: AI_ASSISTANT_CORE_COLLECTION_ALIAS_OPTIONS,
    collection_term_hints: AI_ASSISTANT_CORE_TERM_HINTS
});

//# sourceMappingURL=assistant-core-heuristics.js.map
