import type {ExtractedEntities} from '../promptRouter';
import type {ReportPart} from '@/features/loyaly-ai/types/chat';

export function buildInventoryTemplate(entities: ExtractedEntities): ReportPart {
  return {
    type: 'report',
    title: `Inventory & Stock Reorder Health Report`,
    summary: `Stock analytics for **"${entities.query}"**. 3 fast-moving SKUs are approaching low stock thresholds at **Indiranagar Flagship** and **Koramangala**.`,
    kpis: [
      {id: 'ik1', title: 'Low Stock SKUs', value: '3 Items', trend: 'Reorder needed', iconName: 'alert'},
      {id: 'ik2', title: 'Stock Value', value: '₹14.2L', trend: 'Across 4 stores', iconName: 'revenue'},
      {id: 'ik3', title: 'Turnover Velocity', value: '14 Days', trend: 'Fast-moving', iconName: 'purchases'},
    ],
    tables: [
      {
        title: 'Inventory Stock Alerts & Reorder Points',
        columns: [
          {key: 'item', header: 'Item Description'},
          {key: 'store', header: 'Store'},
          {key: 'stock', header: 'In Stock', align: 'end'},
          {key: 'reorder', header: 'Reorder Point', align: 'end'},
          {key: 'status', header: 'Status', align: 'center'},
        ],
        rows: [
          {item: 'Loyaly Premium Gift Cards', store: 'Indiranagar Flagship', stock: '14 units', reorder: '50 units', status: 'warning'},
          {item: 'VIP Member Lanyards', store: 'Koramangala 80ft', stock: '8 units', reorder: '30 units', status: 'warning'},
          {item: 'POS Thermal Roll Packs', store: 'Jayanagar 4th Block', stock: '42 units', reorder: '20 units', status: 'active'},
        ],
      },
    ],
    insights: [
      {
        id: 'ii1',
        type: 'opportunity',
        title: 'Automated Stock Reorder Recommendation',
        explanation: 'Loyaly Premium Gift Cards are selling 3x faster than average daily forecast.',
        confidence: 95,
        recommendedAction: 'Trigger automatic PO for 100 units from central warehouse.',
      },
    ],
    actions: [
      {id: 'ia1', label: 'Open Integrations Settings', actionType: 'open_dashboard', iconName: 'integrations'},
      {id: 'ia2', label: 'Export Inventory CSV', actionType: 'export_csv', iconName: 'download'},
    ],
  };
}
