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

export const disputeEscalationRule: EscalationRule = {
  id: 'dispute-escalation',
  label: 'הסלמה במחלוקת',
  description: 'גם קונה וגם ספק השתתפו בשיחה (מקרה מסחרי)',
  async check(ctx) {
    if (ctx.parentType !== 'case') return null;

    const hasBuyer = ctx.conversation.some((m) => m.role === 'user' || m.role === 'customer');
    const hasVendor = ctx.conversation.some(
      (m) => m.role === 'vendor' || m.role === 'vendor_internal',
    );

    if (!hasBuyer || !hasVendor) return null;

    return {
      ruleId: 'dispute-escalation',
      reason: 'שיחה כוללת הודעות מקונה ומספק — מחלוקת פעילה',
      severity: 'high',
    };
  },
};
