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

export function buildRewardsTemplate(entities: ExtractedEntities): ReportPart {
  return {
    type: 'report',
    title: `Rewards & LYTs Performance Report`,
    summary: `Analysis of active loyalty campaigns for **"${entities.query}"**. Total claims reached **1,442** this month with a **54.2%** redemption rate. Outstanding LYT liability is currently **1.2L LYTs**.`,
    kpis: [
      {id: 'rk1', title: 'Total Claims', value: '1,442', trend: '+14%', trendDirection: 'up', iconName: 'lyt'},
      {id: 'rk2', title: 'Redemption Rate', value: '54.2%', trend: '+3.1%', trendDirection: 'up', iconName: 'conversion'},
      {id: 'rk3', title: 'Outstanding LYTs', value: '1.2L LYTs', trend: '₹1.2L value', iconName: 'lyt'},
    ],
    tables: [
      {
        title: 'Active Reward Campaigns Breakdown',
        columns: [
          {key: 'campaign', header: 'Campaign Name'},
          {key: 'claims', header: 'Total Claims', align: 'end'},
          {key: 'redemption', header: 'Redemption Rate', align: 'end'},
          {key: 'status', header: 'Status', align: 'center'},
        ],
        rows: [
          {campaign: 'Buy 1 Get 1 Free', claims: '688', redemption: '19.0%', status: 'warning'},
          {campaign: 'Combo 20% Off', claims: '420', redemption: '61.0%', status: 'active'},
          {campaign: 'Weekend Double LYTs', claims: '334', redemption: '74.0%', status: 'active'},
        ],
      },
    ],
    insights: [
      {
        id: 'ri1',
        type: 'opportunity',
        title: 'Shorten BOGO Redemption Expiry',
        explanation: '81% of BOGO claims remain unredeemed after 14 days, creating unfulfilled customer expectations and pending liability.',
        confidence: 94,
        recommendedAction: 'Reduce expiry window from 14 days to 5 days to trigger immediate store visits.',
      },
    ],
    actions: [
      {id: 'ra1', label: 'Manage Rewards & LYTs', actionType: 'view_rewards', iconName: 'lyts'},
      {id: 'ra2', label: 'Export Redemption Log CSV', actionType: 'export_csv', iconName: 'download'},
    ],
  };
}
