import { Purchase } from '../types';

const MOCK_PURCHASES: Purchase[] = [
  {
    id: 'p1',
    orderId: 'ORD-9921',
    date: '2023-10-24',
    price: 29.99,
    status: 'completed',
    downloadUrl: '#',
    license: { id: 'l1', name: 'Standard', price: 29.99, features: [] },
    product: {
      id: 'prod1',
      title: 'Cyberpunk 2077 Drums',
      type: 'pack',
      price: 29.99,
      currency: 'USD',
      rating: 5,
      coverUrl: 'https://picsum.photos/id/120/100/100',
      author: 'Neon Audio',
    } as unknown as any,
  },
  {
    id: 'p2',
    orderId: 'ORD-9850',
    date: '2023-10-15',
    price: 49.99,
    status: 'completed',
    downloadUrl: '#',
    license: { id: 'l2', name: 'Premium', price: 49.99, features: [] },
    product: {
      id: 'prod2',
      title: 'Ethereal Pads Vol. 1',
      type: 'pack',
      price: 49.99,
      currency: 'USD',
      rating: 4,
      coverUrl: 'https://picsum.photos/id/140/100/100',
      author: 'Soundscapes',
    } as unknown as any,
  },
];

const RECENT_SALES = [
  {
    id: 's1',
    product: 'Cyberpunk 2077 Drums',
    date: '2 mins ago',
    amount: 29.99,
    buyer: 'User_992',
  },
  {
    id: 's2',
    product: 'Dark Techno Bunker',
    date: '1 hour ago',
    amount: 49.99,
    buyer: 'TechnoFan',
  },
  {
    id: 's3',
    product: 'Ethereal Pads Vol. 1',
    date: '3 hours ago',
    amount: 14.99,
    buyer: 'AmbientSoul',
  },
  {
    id: 's4',
    product: 'Cyberpunk 2077 Drums',
    date: '5 hours ago',
    amount: 29.99,
    buyer: 'ProducerX',
  },
];

export const commerceService = {
  getPurchases: async () => {
    await new Promise((resolve) => setTimeout(resolve, 600));
    return MOCK_PURCHASES;
  },

  getSales: async () => {
    await new Promise((resolve) => setTimeout(resolve, 500));
    return RECENT_SALES;
  },

  getSellerStats: async () => {
    await new Promise((resolve) => setTimeout(resolve, 400));
    return {
      revenue: 14250,
      sales: 342,
      views: 45200,
      conversion: 3.2,
    };
  },

  requestRefund: async (_orderId: string, _reason: string) => {
    await new Promise((resolve) => setTimeout(resolve, 800));
    return { success: true };
  },
};
