import type { EscalationRule } from './types';

const LEGAL_KEYWORDS =
  /\b(lawyer|court|sue|consumer protection|legal action|attorney)\b|עורך דין|משפטי|בית משפט|הגנת הצרכן|תביעה/i;

export const legalLanguageRule: EscalationRule = {
  id: 'legal-language',
  label: 'שפה משפטית',
  description: 'שיחה מכילה איומים או שפה משפטית',
  async check(ctx) {
    const text = ctx.conversation.map((m) => m.content).join('\n');
    if (!LEGAL_KEYWORDS.test(text)) return null;
    return {
      ruleId: 'legal-language',
      reason: 'זוהתה שפה משפטית או איום בתביעה',
      severity: 'high',
    };
  },
};
