/**
 * Shared Convention Pattern Definitions
 *
 * Canonical pattern list consumed by the Memory factory's runtime
 * interpreter (`generateInterpreterModule` reads them to emit
 * dispatch code). Prisma / Mongo / Postgres step-conventions split
 * off into their own inline-regex files historically and no longer
 * read from here — changes in this file primarily affect Memory.
 *
 * Entity-targeting patterns (find / create / update-field / update /
 * delete) carry a leading-adjective skip
 * `(?:(?:new|existing|current|the|a|an)\s+)?` so an NL step like
 * "Create new Player with …" extracts `Player`, not `new`. Mirrors
 * `NL_LEADING_ADJECTIVES` in `_shared/step-matching.ts`. Without this,
 * Memory's interpreter would call `ctx.store.create("new", data)` and
 * fail at lookup; the structural cause is identical to the TS-side bug
 * that `safeEntityName` (from `@specverse/types`) addresses in the
 * other ORMs — only the *consequence* differs (runtime lookup failure
 * here vs TS syntax error there).
 */

export interface PatternDefinition {
  name: string;
  pattern: RegExp;
  description: string;
}

export const CONVENTION_PATTERNS: PatternDefinition[] = [
  { name: 'validate',         pattern: /^validate\s+(.+)/i,                                    description: 'Validate input data' },
  { name: 'check-no-existing', pattern: /^check\s+(?:no\s+existing|.*has\s+no\s+existing)\s+(\w+)\s+for\s+(\w+)\s+in\s+(\w+)/i, description: 'Check no duplicate entity exists for a pair' },
  { name: 'check',            pattern: /^check\s+(.+)/i,                                       description: 'Check a condition' },
  { name: 'find',             pattern: /^find\s+(?:(?:new|existing|current|the|a|an)\s+)?(\w+)\s+by\s+(\w+)/i, description: 'Find entity by field' },
  { name: 'find-all-for',     pattern: /^find\s+(?:all\s+)?(\w+?)s?\s+(?:for|of|belonging\s+to)\s+(\w+)/i, description: 'Cross-model query via foreign key' },
  { name: 'count-per',        pattern: /^count\s+(\w+?)s?\s+(?:per|by|for\s+each)\s+(\w+)/i,   description: 'Group-by aggregation count' },
  { name: 'create',           pattern: /^create\s+(?:(?:new|existing|current|the|a|an)\s+)?(\w+)(?:\s+record)?/i, description: 'Create a new entity' },
  { name: 'update-field',     pattern: /^update\s+(?:(?:new|existing|current|the|a|an)\s+)?(\w+)\s+(\w+)\s+to\s+(.+)/i, description: 'Update specific field to value' },
  { name: 'update',           pattern: /^update\s+(?:(?:new|existing|current|the|a|an)\s+)?(\w+)$/i, description: 'Update entity with params' },
  { name: 'delete',           pattern: /^delete\s+(?:(?:new|existing|current|the|a|an)\s+)?(\w+)/i, description: 'Delete an entity' },
  { name: 'transition',       pattern: /^transition\s+(\w+)\s+to\s+(\w+)/i,                    description: 'Lifecycle state transition' },
  { name: 'set',              pattern: /^set\s+(\w+)\s+to\s+(.+)/i,                            description: 'Set a field value' },
  { name: 'increment',        pattern: /^increment\s+(\w+)\s+by\s+(\w+)/i,                     description: 'Increment numeric field' },
  { name: 'decrement',        pattern: /^decrement\s+(\w+)\s+by\s+(\w+)/i,                     description: 'Decrement numeric field' },
  { name: 'calculate',        pattern: /^calculate\s+(.+)/i,                                   description: 'Calculate metric or aggregation' },
  { name: 'send-event',       pattern: /^(?:send|emit|publish)\s+(\w+)\s+event/i,              description: 'Publish domain event' },
  { name: 'send-notification', pattern: /^send\s+(\w+)\s+notification/i,                       description: 'Send notification event' },
  { name: 'call-service',     pattern: /^call\s+(\w+)\.(\w+)/i,                                description: 'Delegate to another service' },
  { name: 'return',           pattern: /^return\s+(.+)/i,                                      description: 'Return a value' },
];
