import { formatAgorotShekels } from '@/lib/money.js';
import type { EscalationRule } from './types';

const HIGH_VALUE_AGOROT = 50_000;

export const highValueOrderRule: EscalationRule = {
  id: 'high-value-order',
  label: 'הזמנה בעלת ערך גבוה',
  description: 'רכישה מקושרת מעל ₪500',
  async check(ctx) {
    const orderChunk = ctx.knowledgeChunks.find((c) => c.adapterId === 'order-context');
    const amountAgorot = orderChunk?.data.amountAgorot;
    if (typeof amountAgorot !== 'number' || amountAgorot <= HIGH_VALUE_AGOROT) return null;
    return {
      ruleId: 'high-value-order',
      reason: `סכום רכישה ${formatAgorotShekels(amountAgorot)} מעל סף ₪500`,
      severity: 'medium',
    };
  },
};
