export const METHOD_ACTIONS = {
    "POST": ["create", "add", "new", "register", "upload", "generate", "insert"],
    "GET": ["read", "get", "fetch", "find", "search", "list", "show", "details"],
    "PUT": ["update", "modify", "edit", "change", "save", "set", "refresh", "renew", "upgrade"],
    "PATCH": ["update", "modify", "edit", "change", "save", "set", "adjust", "alter", "tweak"],
    "DELETE": ["delete", "remove", "erase", "destroy", "clear", "cancel", "archive", "unlink"],
    "MONITOR": ["monitor", "track", "audit", "inspect", "history", "logs", "usage", "metrics", "stats"] // [R15]
};
// [Final Plan] Single Source of Truth for Resource Synonyms
// Maps ResourceType (Schema) -> Aliases (User Input / Search Terms)
export const RESOURCE_ALIASES = {
    // Core Entities
    // Core Entities
    'division': ['organization', 'org', 'department', 'group', 'sector', 'unit', 'authorized division'], // [R34] Added authorized division alias
    'authorized-division': ['authorized division', 'division permission', 'division access', 'access permission', 'authorized divisions'], // [R34] New authorized divisions resource
    'knowledge': ['knowledge', 'knowledge base'], // [R17] New Resource Support
    'document-category': ['category', 'document category', 'doc category', 'file category'], // [R22] Document category filtering
    'project': ['workspace', 'repo', 'application', 'app'], // [R13] Removed 'system' to avoid conflict
    'system': ['system', 'health', 'status', 'health check', 'heartbeat', 'ping', 'deployment'],
    'context-version': ['context version', 'context-version', 'build version', 'deployment version'], // Dedicated sub-resource
    'auth': ['security', 'credential', 'token', 'access', 'password'], // [R17] Removed 'login' to avoid conflict with action
    'oauth': ['third party', 'social login', 'google', 'github', 'oauth'], // [R17] Dedicated OAuth resource
    // FMEA Domain
    'failure-mode': ['failure', 'mode', 'fmea', 'cause', 'effect', 'defect', 'error', 'fault', 'mistake'], // [R17] Removed 'category'
    'block-diagram': ['block', 'diagram', 'bd', 'structure', 'architecture'],
    'worksheet': ['sheet', 'tab', 'page', 'table'], // [R16] Removed 'excel', 'spreadsheet' (dedicated resource)
    'block-node': ['node', 'component', 'element', 'part', 'block diagram nodes'], // [R13] Explicit Support — removed 'item' to avoid conflict with high-item
    'fault-tree': ['fault tree', 'fta', 'fault analysis', 'analysis'], // [R16] New dedicated resource for FTA
    // System
    'admin-user': ['admin', 'admin user', 'administration', 'manage user', 'user management'], // [R19] Dedicated admin-user resource
    'user': ['person', 'account', 'profile'], // Removed 'member' from here to avoid conflict
    'member': ['member', 'project member', 'team'], // [R13] Distinct resource type matching indexer
    'document': ['file', 'attachment', 'upload', 'paperwork', 'files'], // [R13] Added plural 'files'
    'api-key': ['key', 'secret', 'credential', 'authenticate', 'client auth', 'client credential', 'api key'], // [R15] [R22] [R40] Added 'api key' for explicit phrase match
    'worksheet-template': ['template', 'sheet structure', 'configuration'], // [R18] [R26] Added 'configuration' for template setup queries
    'action-status-template': ['status template', 'action status'], // [R15]
    'join-request': ['join', 'invite', 'add user', 'member request', 'pending', 'join request'], // [R16]
    'fmm-diagram': ['fmm', 'fmm diagram', 'failure mode diagram', 'causal diagram'], // [R19] Dedicated FMM diagram resource
    'excel': ['excel', 'csv'], // [R16] Removed 'spreadsheet' — it's a trigger for resource-specific excel export heuristics
    'worksheet-excel': ['worksheet excel', 'excel worksheet', 'worksheet export', 'worksheet download'], // Worksheet Excel import/export
    'block-diagrams-excel': ['block diagram export', 'block excel', 'diagram export', 'export block', 'export diagram', 'export'], // [R22] Block Diagram Excel export
    'synonym': ['synonyms', 'synonym', 'synonym group', 'synonym dictionary', 'term group'], // [R34] Enhanced synonym aliases
    'synonym-excel': ['synonym excel', 'synonym export', 'synonym import', 'synonym spreadsheet'], // [R34] Synonym Excel import/export
    'system-settings': ['system settings', 'system config', 'system configuration', 'global settings'], // [R34] System settings resource
    'recommendation-item': ['recommendation item', 'recommended action', 'corrective action', 'action item', 'mitigation item'], // [R20] New v2 recommendation items
    'fourm': ['4m', 'four m', '4m analysis', 'man machine material environment'], // 4M Analysis
    'term': ['term', 'terms', 'taxonomy', 'terminology', 'glossary'], // Term tree management — removed 'classification' (now dedicated resource [R28])
    'condition-library': ['condition library', 'stress condition', 'design condition', 'process condition', 'stress library', 'design library', 'process library', 'factor', 'common term', 'common terms', 'shared term'], // [R24] [R38] Added factor/common term aliases
    'system-definition': ['system definition', 'system def', 'sys def', 'system spec', 'system specification', 'system function', 'system requirement'], // [R21] New system definition resource — removed 'condition/conditions' to avoid conflict with condition-library
    'system-definition-excel': ['system definition excel', 'system definition import', 'system definition export', 'conditions export', 'conditions import', 'export conditions', 'import conditions'], // [R23] Excel import/export for system definition conditions
    'high-item': ['high item', 'high items', 'high priority item', 'high priority risk', 'high priority', 'top item', 'top risk', 'risk ranking', 'high risk', 'priority list', 'batch upsert items', 'reorder items'], // [R23] High items resource
    'workspace-bootstrap': ['bootstrap', 'workspace bootstrap', 'workspace init', 'workspace setup'], // [R21] Workspace bootstrap data
    'search-failure-mode': ['global failure mode', 'search failure mode', 'failure mode search', 'global search failure', 'cross-project failure mode'], // [R25] Global failure mode search
    'dashboard': ['dashboard', 'dashboard summary', 'my projects summary', 'projects overview', 'action items', 'overdue', 'rpn distribution', 'project status'], // [R25] [R29] Dashboard summary resource
    'evaluation': ['evaluation', 'evaluation criteria', 'assessment', 'rating criteria', 'grading'], // [R27] Evaluation criteria resource — removed 'scoring criteria' (now dedicated resource [R30])
    'significance-criteria': ['significance criteria', 'significance', 'sod threshold', 'rpn threshold', 'severity occurrence detection', 'sod criteria', 'sod', 'rpn', 'sod rpn'], // [R27] [R33] Added SOD/RPN shorthand
    'classification': ['classification', 'classification group', 'classification item', 'symbol', 'label group', 'risk classification', 'project classification'], // [R28] [R29] Classification groups and items
    'fm-checkpoint': ['fm checkpoint', 'failure mode checkpoint', 'checkpoint', 'checklist', 'check item'], // [R30] FM Checkpoint tree management
    'scoring-criteria': ['scoring criteria', 'scoring', 'score criteria', 'completeness scoring', 'scoring tree'], // [R30] Scoring criteria tree management
    'process-symbol': ['process symbol', 'process symbols', 'flow chart symbol', 'flowchart symbol', 'process flow'], // [R30] Process flow chart symbols
    'additional-info': ['additional info', 'additional information', 'extra info', 'supplementary info', 'custom field', 'custom attribute', 'form field'], // [R31] Additional info template management
    'approval': ['approval board', 'approval request', 'approval decisions', 'approval progress', 'approve or refuse', 'request approval', 'review workflow', 'submit approval', 'approve'], // [R39] Approval workflow
    'board': ['board comment', 'board discussion', 'discussion board', 'comment thread', 'review comment', 'discussion', 'comment board'], // [R39] Board comments/discussion
    'notice': ['notice', 'notices', 'announcement', 'bulletin', 'notification'], // [R32] Notice CRUD and visibility
    'tree-search': ['tree search', 'tree query', 'structure search', 'pattern search', 'subtree match', 'anchor pattern', 'context completion', 'reference node', 'rebuild index', 'reindex'], // [R35] Tree search query and index rebuild
    // [R40] New Excel export endpoints
    'additional-info-excel': ['additional info excel', 'additional information excel', 'export additional info', 'additional info export', 'additional fields spreadsheet'],
    'api-key-excel': ['api key excel', 'api keys excel', 'export api keys', 'api key export', 'keys spreadsheet'],
    'apikey-log-excel': ['api key log excel', 'api key audit excel', 'export api key logs', 'api key audit export', 'key log spreadsheet', 'api key audit', 'api key log', 'api key usage log', 'apikey audit log'],
    'classification-excel': ['classification excel', 'export classification', 'classification export', 'classification groups excel'],
    'division-excel': ['division excel', 'export divisions', 'divisions excel', 'division export', 'divisions spreadsheet'],
    'evaluation-excel': ['evaluation excel', 'evaluation export', 'export evaluation', 'criteria excel', 'evaluation criteria excel'],
    'notice-excel': ['notice excel', 'notices excel', 'export notices', 'notice export', 'announcements excel'],
    'process-symbol-excel': ['process symbol excel', 'process symbols excel', 'export process symbols', 'process symbol export'],
    'user-excel': ['user excel', 'users excel', 'export users', 'user list excel', 'users spreadsheet', 'user list spreadsheet'],
    'worksheet-template-excel': ['worksheet template excel', 'template excel', 'export worksheet templates', 'worksheet templates spreadsheet'],
    // [R40] Revision history
    'revision': ['revision history', 'change history', 'change log', 'edit history', 'project history', 'version history', 'audit history', 'revisions'],
};
export const SYNONYM_GROUPS = {
    // Read / Retrieve
    "get": ["fetch", "retrieve", "read", "load", "find", "search", "query", "list", "show", "details"],
    "find": ["get", "search", "retrieve", "lookup", "show", "detect", "locate"],
    "search": ["find", "get", "lookup", "query", "show", "explore", "scan"], // [R38] moved "query" to pos4 to avoid false path-boost on /tree-search/.../query
    "show": ["get", "display", "view", "fetch", "find", "present"],
    "list": ["get", "all", "collection", "show", "summary", "index", "catalog"],
    "summary": ["list", "all", "overview", "collection", "report", "stats"],
    // Create
    "create": ["add", "insert", "make", "new", "post", "generate", "build", "init"],
    "add": ["create", "insert", "append", "attach", "include", "push"],
    "post": ["create", "add", "submit", "send", "upload"],
    "generate": ["create", "make", "build", "produce", "render"],
    // Update
    "update": ["modify", "edit", "change", "save", "put", "patch", "set", "refresh", "renew", "upgrade"],
    "modify": ["update", "edit", "change", "adjust", "alter", "tweak"],
    "save": ["update", "store", "persist", "write", "record", "commit"],
    "replace": ["overwrite", "substitute", "swap", "update", "save", "put"], // [R38] replace → save/update for bulk-replace endpoints
    "set": ["update", "assign", "define", "configure", "specify"],
    // Delete
    "delete": ["remove", "destroy", "clear", "erase", "drop", "cancel", "archive", "unlink"],
    "remove": ["delete", "detach", "discard", "exclude", "strip"],
    "bulk": ["batch", "multiple", "mass", "many", "group", "several"], // [R40] bulk → batch for batch-delete endpoints
    "several": ["multiple", "batch", "bulk", "many", "group"], // [R40] several → batch
    // Processing / Execution (New)
    "parse": ["parsing", "read", "decode", "interpret", "analyze", "extract", "scan"],
    "parsing": ["parse", "reading", "decoding", "interpreting", "analyzing"],
    "process": ["processing", "run", "execute", "handle", "compute", "perform", "analyzing"],
    "processing": ["process", "running", "execution", "handling", "computing"],
    "execute": ["run", "launch", "start", "trigger", "invoke", "call", "process"],
    "run": ["execute", "start", "launch", "go", "process"],
    "rebuild": ["reindex", "regenerate", "recreate", "refresh index", "reconstruct"], // [R36] Index rebuild
    "reindex": ["rebuild", "regenerate", "recreate", "refresh index", "reconstruct"], // [R36]
    // File / Data Handling (New)
    "upload": ["post", "send", "import", "attach", "submit"],
    "import": ["upload", "include", "load", "read", "ingest"],
    "export": ["download", "save", "extract", "dump", "backup"],
    "backup": ["export", "dump", "snapshot", "data"],
    "download": ["get", "fetch", "retrieve", "export", "pull"],
    "copy": ["duplicate", "clone", "replicate", "mirror"],
    "move": ["transfer", "relocate", "rename", "shift", "migrate"],
    // Auth / Security (New)
    "auth": ["authentication", "login", "signin", "verify", "check", "token", "credential"],
    "authenticate": ["auth", "login", "signin", "api key", "credential", "client"], // [R22] authenticate -> api-key
    "login": ["signin", "auth", "authenticate", "connect", "access"],
    "logout": ["signout", "disconnect", "exit", "leave"],
    "verify": ["check", "validate", "confirm", "auth", "authorize", "test"],
    "check": ["verify", "validate", "test", "inspect", "assess", "status"],
    // General / Utilities (New)
    "config": ["configuration", "settings", "setup", "options", "preferences", "profile"],
    "settings": ["config", "preferences", "options", "profile", "properties"],
    "connect": ["link", "join", "pair", "attach", "login", "bind"],
    "disconnect": ["unlink", "detach", "logout", "close", "break"],
    // Domain Specific (New)
    "organization": ["division", "department", "group", "team", "unit"],
    "division": ["organization", "department", "group", "section", "sector"],
    "permission": ["access", "authorization", "authority", "privilege", "right"], // [R34]
    "authorized": ["permitted", "allowed", "approved", "access control"], // [R34]
    "overview": ["summary", "description", "details", "info", "profile", "dashboard"],
    "dashboard": ["overview", "summary", "stats", "metrics", "report", "my projects", "action items", "rpn"], // [R25]
    "globally": ["global", "cross-project", "all projects", "system-wide"], // [R25]
    "mistakes": ["failure", "error", "defect", "fault", "bug", "issue", "problem", "mode"],
    "failure": ["mistake", "error", "defect", "fault", "crash", "breakdown", "mode"],
    // FMEA Domain Specific
    // FMEA Domain Specific
    "hierarchy": ["tree", "nested", "parent", "children", "structure"], // [R24] hierarchy -> tree view
    "tree": ["hierarchy", "nested", "parent", "children", "structure"], // [R24] tree view
    "mode": ["failure", "type", "kind"], // [R17] Removed 'category'
    "category": ["document category", "knowledge", "kind", "type", "classification", "filter"], // [R17] [R22] Category maps to document-category and knowledge
    "recommendation": ["action", "item", "mitigation", "risk", "reduction", "improvement", "corrective"],
    "recommendations": ["actions", "items", "mitigations", "risks", "improvements", "corrective actions"],
    "corrective": ["recommendation", "action", "mitigation", "fix", "remedy"], // [R20]
    // New Domain Terms (from Analysis)
    "excel": ["spreadsheet", "worksheet", "csv", "table", "report"], // [R14 Cleanup] Removed import/export actions
    "worksheet": ["excel", "sheet", "tab", "page"],
    "column": ["header", "field", "attribute", "property", "name"],
    "header": ["column", "field", "title", "label", "heading"],
    "diagram": ["fmm", "chart", "visual", "schema", "model", "structure"], // [R19] Helps "failure mode diagram" → fmm-diagram
    "fmm": ["failure mode diagram", "fmm diagram", "causal diagram", "failure model"], // [R19]
    "node": ["item", "element", "component", "vertex", "point", "unit"],
    "project": ["workspace", "repository", "app", "application"],
    "specific": ["particular", "precise", "exact", "detailed", "single"],
    // System Definition Domain
    "system definition": ["system spec", "system specification", "sys def", "system config"], // [R21]
    "condition": ["conditions", "constraint", "criteria", "rule"], // [R21] removed "requirement"/"specification" to avoid false-match with system-definition/summary [R24]
    "bootstrap": ["init", "initialize", "setup", "startup", "initial data"], // [R21]
    // Targeted Fixes for "Zero Red" Benchmark
    "join": ["add user", "invite", "subscribe", "member request", "join-requests"],
    "documents": ["file", "folder", "directory", "archive", "paperwork"],
    // [R22] New fixes
    "work": ["nodes", "block nodes", "diagram", "fmm", "block diagram nodes"], // "save work" -> block-diagram nodes / fmm-diagram resources
    "client": ["api key", "credential", "authenticate", "auth"], // "authenticate client" -> api-key
    // [R27] Evaluation Criteria Domain
    "evaluation": ["assessment", "criteria", "rating", "grading", "scoring"],
    "assessment": ["evaluation", "criteria", "rating", "grading", "appraisal"],
    "significance": ["importance", "priority", "criticality", "severity", "weight"],
    "threshold": ["limit", "boundary", "cutoff", "criteria", "target"],
    "rpn": ["risk priority number", "risk score", "risk ranking"],
    "display": ["visibility", "show", "hide", "toggle", "visible"],
    "default": ["preset", "standard", "baseline", "initial"],
    "refresh": ["reload", "update", "recalculate", "regenerate", "sync"],
    "regenerate": ["rebuild", "reindex", "refresh", "renew", "rotate", "reissue"], // [R33] [R37] rebuild/reindex first to rank within slice(0,3) limit
    "snapshot": ["cache", "refresh", "summary", "data snapshot"],
    // [R28] Classification Domain
    "classification": ["category", "label", "symbol", "group", "class", "tag"],
    "symbol": ["icon", "marker", "badge", "image", "label"],
    // [R30] FM Checkpoint & Scoring Domain
    "checkpoint": ["checklist", "check item", "verification", "audit item"],
    "breadcrumb": ["path", "navigation", "ancestor", "경로", "trail"], // [R31] Removed "hierarchy path" to avoid boosting /tree endpoints
    // [R39] Approval & Board Domain
    "approval": ["approve", "authorization", "sign-off", "decision", "review request"],
    "approve": ["authorize", "accept", "confirm", "approval", "sign off"],
    "refuse": ["reject", "deny", "decline", "disapprove", "refusal"],
    "decision": ["approve", "refuse", "verdict", "choice"],
    "board": ["comment", "discussion", "thread", "forum"],
    "comment": ["board", "remark", "note", "opinion"],
    "discussion": ["comment", "thread", "board", "conversation"],
    "reply": ["response", "comment", "feedback", "answer"],
    "thread": ["discussion", "comments", "replies", "chain"],
    // [R31] Korean Term Mappings
    "조회": ["get", "list", "view", "fetch", "search", "retrieve", "read", "show"],
    "경로": ["breadcrumb", "path", "navigation", "route", "trail"],
    "삭제": ["delete", "remove", "erase", "destroy"],
    "변경": ["update", "modify", "change", "edit"],
    "생성": ["create", "add", "new", "register"],
    "목록": ["list", "all", "collection", "index"],
    "수정": ["update", "modify", "edit", "change"],
    "추가": ["add", "create", "insert", "append"],
    "검색": ["search", "find", "query", "lookup"],
};
/**
 * Expands a single token into a list of synonyms including itself.
 */
export function getSynonyms(token) {
    const lowerToken = token.toLowerCase();
    // Direct lookup
    if (SYNONYM_GROUPS[lowerToken]) {
        return [lowerToken, ...SYNONYM_GROUPS[lowerToken]];
    }
    // Reverse lookup (inefficient but thorough for a small map)
    const synonyms = new Set();
    synonyms.add(lowerToken);
    for (const [key, details] of Object.entries(SYNONYM_GROUPS)) {
        if (details.includes(lowerToken)) {
            synonyms.add(key);
            details.forEach(d => synonyms.add(d));
        }
    }
    return Array.from(synonyms);
}
