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

export function buildAnalyticsTemplate(entities: ExtractedEntities): ReportPart {
  return {
    type: 'report',
    title: `Retail Analytics & Customer Retention Report`,
    summary: `90-day retention and cohort analysis for **"${entities.query}"**. Repeat visit rate sits at **38%** with a median visit cycle of 17 days. 1,240 previously active buyers are flagged as at-risk.`,
    kpis: [
      {id: 'ak1', title: '90-Day Repeat Rate', value: '38.0%', trend: '+1.8%', trendDirection: 'up', iconName: 'conversion'},
      {id: 'ak2', title: 'Median Visit Gap', value: '17 Days', trend: '-2 Days', trendDirection: 'up', iconName: 'sessions'},
      {id: 'ak3', title: 'At-Risk Cohort', value: '1,240', trend: '₹2.1L Spend', iconName: 'alert'},
    ],
    insights: [
      {
        id: 'ai1',
        type: 'opportunity',
        title: 'At-Risk Customer Recovery Campaign',
        explanation: '1,240 customers who spent ₹2.1L have not visited in 45+ days. A targeted 100-LYT bonus will recover an estimated ₹85,000 in revenue.',
        confidence: 95,
        recommendedAction: 'Launch Automated Winback Campaign in LYT Rewards Manager.',
      },
    ],
    actions: [
      {id: 'aa1', label: 'View Rewards Manager', actionType: 'view_rewards', iconName: 'lyts'},
      {id: 'aa2', label: 'Export Cohort CSV', actionType: 'export_csv', iconName: 'download'},
    ],
  };
}
