/**
 * Dummy Revenue Data
 * Structure matches /woonoow/v1/analytics/revenue API response
 */

export interface RevenueOverview {
  gross_revenue: number;
  net_revenue: number;
  tax: number;
  shipping: number;
  refunds: number;
  change_percent: number;
  previous_gross_revenue: number;
  previous_net_revenue: number;
}

export interface RevenueChartData {
  date: string;
  gross: number;
  net: number;
  refunds: number;
  tax: number;
  shipping: number;
}

export interface RevenueByProduct {
  id: number;
  name: string;
  revenue: number;
  orders: number;
  refunds: number;
  net_revenue: number;
}

export interface RevenueByCategory {
  id: number;
  name: string;
  revenue: number;
  percentage: number;
  orders: number;
}

export interface RevenueByPaymentMethod {
  method: string;
  method_title: string;
  orders: number;
  revenue: number;
  percentage: number;
}

export interface RevenueByShippingMethod {
  method: string;
  method_title: string;
  orders: number;
  revenue: number;
  percentage: number;
}

export interface RevenueData {
  overview: RevenueOverview;
  chart_data: RevenueChartData[];
  by_product: RevenueByProduct[];
  by_category: RevenueByCategory[];
  by_payment_method: RevenueByPaymentMethod[];
  by_shipping_method: RevenueByShippingMethod[];
}

// Generate 30 days of revenue data
const generateChartData = (): RevenueChartData[] => {
  const data: RevenueChartData[] = [];
  const today = new Date();
  
  for (let i = 29; i >= 0; i--) {
    const date = new Date(today);
    date.setDate(date.getDate() - i);
    
    const baseRevenue = 8000000 + Math.random() * 8000000;
    const refunds = baseRevenue * (0.02 + Math.random() * 0.03);
    const tax = baseRevenue * 0.11;
    const shipping = 150000 + Math.random() * 100000;
    
    data.push({
      date: date.toISOString().split('T')[0],
      gross: Math.round(baseRevenue),
      net: Math.round(baseRevenue - refunds),
      refunds: Math.round(refunds),
      tax: Math.round(tax),
      shipping: Math.round(shipping),
    });
  }
  
  return data;
};

export const DUMMY_REVENUE_DATA: RevenueData = {
  overview: {
    gross_revenue: 344750000,
    net_revenue: 327500000,
    tax: 37922500,
    shipping: 6750000,
    refunds: 17250000,
    change_percent: 15.3,
    previous_gross_revenue: 299000000,
    previous_net_revenue: 284050000,
  },
  chart_data: generateChartData(),
  by_product: [
    {
      id: 1,
      name: 'Wireless Headphones Pro',
      revenue: 72000000,
      orders: 24,
      refunds: 1500000,
      net_revenue: 70500000,
    },
    {
      id: 2,
      name: 'Smart Watch Series 5',
      revenue: 54000000,
      orders: 18,
      refunds: 800000,
      net_revenue: 53200000,
    },
    {
      id: 3,
      name: 'USB-C Hub 7-in-1',
      revenue: 32000000,
      orders: 32,
      refunds: 400000,
      net_revenue: 31600000,
    },
    {
      id: 4,
      name: 'Mechanical Keyboard RGB',
      revenue: 22500000,
      orders: 15,
      refunds: 300000,
      net_revenue: 22200000,
    },
    {
      id: 5,
      name: 'Wireless Mouse Gaming',
      revenue: 16800000,
      orders: 28,
      refunds: 200000,
      net_revenue: 16600000,
    },
    {
      id: 6,
      name: 'Laptop Stand Aluminum',
      revenue: 12400000,
      orders: 22,
      refunds: 150000,
      net_revenue: 12250000,
    },
    {
      id: 7,
      name: 'Webcam 4K Pro',
      revenue: 18500000,
      orders: 12,
      refunds: 500000,
      net_revenue: 18000000,
    },
    {
      id: 8,
      name: 'Portable SSD 1TB',
      revenue: 28000000,
      orders: 16,
      refunds: 600000,
      net_revenue: 27400000,
    },
  ],
  by_category: [
    {
      id: 1,
      name: 'Electronics',
      revenue: 186500000,
      percentage: 54.1,
      orders: 142,
    },
    {
      id: 2,
      name: 'Accessories',
      revenue: 89200000,
      percentage: 25.9,
      orders: 98,
    },
    {
      id: 3,
      name: 'Computer Parts',
      revenue: 52800000,
      percentage: 15.3,
      orders: 64,
    },
    {
      id: 4,
      name: 'Gaming',
      revenue: 16250000,
      percentage: 4.7,
      orders: 38,
    },
  ],
  by_payment_method: [
    {
      method: 'bca_va',
      method_title: 'BCA Virtual Account',
      orders: 156,
      revenue: 172375000,
      percentage: 50.0,
    },
    {
      method: 'mandiri_va',
      method_title: 'Mandiri Virtual Account',
      orders: 98,
      revenue: 103425000,
      percentage: 30.0,
    },
    {
      method: 'gopay',
      method_title: 'GoPay',
      orders: 52,
      revenue: 41370000,
      percentage: 12.0,
    },
    {
      method: 'ovo',
      method_title: 'OVO',
      orders: 36,
      revenue: 27580000,
      percentage: 8.0,
    },
  ],
  by_shipping_method: [
    {
      method: 'jne_reg',
      method_title: 'JNE Regular',
      orders: 186,
      revenue: 189825000,
      percentage: 55.0,
    },
    {
      method: 'jnt_reg',
      method_title: 'J&T Regular',
      orders: 98,
      revenue: 103425000,
      percentage: 30.0,
    },
    {
      method: 'sicepat_reg',
      method_title: 'SiCepat Regular',
      orders: 42,
      revenue: 34475000,
      percentage: 10.0,
    },
    {
      method: 'pickup',
      method_title: 'Store Pickup',
      orders: 16,
      revenue: 17025000,
      percentage: 5.0,
    },
  ],
};
