/**
 * Dummy Customers Analytics Data
 * Structure matches /woonoow/v1/analytics/customers API response
 */

export interface CustomersOverview {
  total_customers: number;
  new_customers: number;
  returning_customers: number;
  avg_ltv: number;
  retention_rate: number;
  avg_orders_per_customer: number;
  change_percent: number;
}

export interface CustomerSegments {
  new: number;
  returning: number;
  vip: number;
  at_risk: number;
}

export interface TopCustomer {
  id: number;
  name: string;
  email: string;
  orders: number;
  total_spent: number;
  avg_order_value: number;
  last_order_date: string;
  segment: 'new' | 'returning' | 'vip' | 'at_risk';
  days_since_last_order: number;
}

export interface CustomerAcquisitionData {
  date: string;
  new_customers: number;
  returning_customers: number;
}

export interface LTVDistribution {
  range: string;
  min: number;
  max: number;
  count: number;
  percentage: number;
}

export interface CustomersData {
  overview: CustomersOverview;
  segments: CustomerSegments;
  top_customers: TopCustomer[];
  acquisition_chart: CustomerAcquisitionData[];
  ltv_distribution: LTVDistribution[];
}

// Generate 30 days of customer acquisition data
const generateAcquisitionData = (): CustomerAcquisitionData[] => {
  const data: CustomerAcquisitionData[] = [];
  const today = new Date();
  
  for (let i = 29; i >= 0; i--) {
    const date = new Date(today);
    date.setDate(date.getDate() - i);
    
    const newCustomers = Math.floor(5 + Math.random() * 15);
    const returningCustomers = Math.floor(15 + Math.random() * 25);
    
    data.push({
      date: date.toISOString().split('T')[0],
      new_customers: newCustomers,
      returning_customers: returningCustomers,
    });
  }
  
  return data;
};

export const DUMMY_CUSTOMERS_DATA: CustomersData = {
  overview: {
    total_customers: 842,
    new_customers: 186,
    returning_customers: 656,
    avg_ltv: 4250000,
    retention_rate: 68.5,
    avg_orders_per_customer: 2.8,
    change_percent: 14.2,
  },
  segments: {
    new: 186,
    returning: 524,
    vip: 98,
    at_risk: 34,
  },
  top_customers: [
    {
      id: 1,
      name: 'Budi Santoso',
      email: 'budi.santoso@email.com',
      orders: 28,
      total_spent: 42500000,
      avg_order_value: 1517857,
      last_order_date: '2025-11-02',
      segment: 'vip',
      days_since_last_order: 1,
    },
    {
      id: 2,
      name: 'Siti Nurhaliza',
      email: 'siti.nur@email.com',
      orders: 24,
      total_spent: 38200000,
      avg_order_value: 1591667,
      last_order_date: '2025-11-01',
      segment: 'vip',
      days_since_last_order: 2,
    },
    {
      id: 3,
      name: 'Ahmad Wijaya',
      email: 'ahmad.w@email.com',
      orders: 22,
      total_spent: 35800000,
      avg_order_value: 1627273,
      last_order_date: '2025-10-30',
      segment: 'vip',
      days_since_last_order: 4,
    },
    {
      id: 4,
      name: 'Dewi Lestari',
      email: 'dewi.lestari@email.com',
      orders: 19,
      total_spent: 28900000,
      avg_order_value: 1521053,
      last_order_date: '2025-11-02',
      segment: 'vip',
      days_since_last_order: 1,
    },
    {
      id: 5,
      name: 'Rudi Hartono',
      email: 'rudi.h@email.com',
      orders: 18,
      total_spent: 27400000,
      avg_order_value: 1522222,
      last_order_date: '2025-10-28',
      segment: 'returning',
      days_since_last_order: 6,
    },
    {
      id: 6,
      name: 'Linda Kusuma',
      email: 'linda.k@email.com',
      orders: 16,
      total_spent: 24800000,
      avg_order_value: 1550000,
      last_order_date: '2025-11-01',
      segment: 'returning',
      days_since_last_order: 2,
    },
    {
      id: 7,
      name: 'Eko Prasetyo',
      email: 'eko.p@email.com',
      orders: 15,
      total_spent: 22600000,
      avg_order_value: 1506667,
      last_order_date: '2025-10-25',
      segment: 'returning',
      days_since_last_order: 9,
    },
    {
      id: 8,
      name: 'Maya Sari',
      email: 'maya.sari@email.com',
      orders: 14,
      total_spent: 21200000,
      avg_order_value: 1514286,
      last_order_date: '2025-11-02',
      segment: 'returning',
      days_since_last_order: 1,
    },
    {
      id: 9,
      name: 'Hendra Gunawan',
      email: 'hendra.g@email.com',
      orders: 12,
      total_spent: 18500000,
      avg_order_value: 1541667,
      last_order_date: '2025-10-29',
      segment: 'returning',
      days_since_last_order: 5,
    },
    {
      id: 10,
      name: 'Rina Wati',
      email: 'rina.wati@email.com',
      orders: 11,
      total_spent: 16800000,
      avg_order_value: 1527273,
      last_order_date: '2025-11-01',
      segment: 'returning',
      days_since_last_order: 2,
    },
  ],
  acquisition_chart: generateAcquisitionData(),
  ltv_distribution: [
    {
      range: '< Rp1.000.000',
      min: 0,
      max: 1000000,
      count: 186,
      percentage: 22.1,
    },
    {
      range: 'Rp1.000.000 - Rp5.000.000',
      min: 1000000,
      max: 5000000,
      count: 342,
      percentage: 40.6,
    },
    {
      range: 'Rp5.000.000 - Rp10.000.000',
      min: 5000000,
      max: 10000000,
      count: 186,
      percentage: 22.1,
    },
    {
      range: 'Rp10.000.000 - Rp20.000.000',
      min: 10000000,
      max: 20000000,
      count: 84,
      percentage: 10.0,
    },
    {
      range: '> Rp20.000.000',
      min: 20000000,
      max: 999999999,
      count: 44,
      percentage: 5.2,
    },
  ],
};
