export interface Shop {
  name: string;
  slug: string;
  url: string;
}

export interface ShopOffer {
  shop: string;
  price: number;
  originalPrice?: number;
  url: string;
  inStock: boolean;
  sizes: number[];
}

export interface Sneaker {
  id: string;
  slug: string;
  name: string;
  brand: string;
  brandSlug: string;
  colorway: string;
  image: string;
  lowestPrice: number;
  originalPrice: number;
  offers: ShopOffer[];
  sizes: number[];
  gender: 'heren' | 'dames' | 'unisex';
  releaseDate: string;
  trending: boolean;
  priceDrop: boolean;
  priceHistory: { date: string; price: number }[];
}

export interface Brand {
  name: string;
  slug: string;
  logo: string;
  color: string;
}

export const shops: Shop[] = [
  { name: 'Patta', slug: 'patta', url: 'https://patta.nl' },
  { name: 'BSTN', slug: 'bstn', url: 'https://bstn.com' },
  { name: 'Footlocker', slug: 'footlocker', url: 'https://footlocker.nl' },
  { name: 'JD Sports', slug: 'jd-sports', url: 'https://jdsports.nl' },
  { name: 'Zalando', slug: 'zalando', url: 'https://zalando.nl' },
  { name: 'Sneaker District', slug: 'sneaker-district', url: 'https://sneakerdistrict.nl' },
  { name: 'Solebox', slug: 'solebox', url: 'https://solebox.com' },
  { name: 'About You', slug: 'about-you', url: 'https://aboutyou.nl' },
];

export const brands: Brand[] = [
  { name: 'Nike', slug: 'nike', logo: '', color: '#F56B00' },
  { name: 'Adidas', slug: 'adidas', logo: '', color: '#1A1A1A' },
  { name: 'New Balance', slug: 'new-balance', logo: '', color: '#CF0A2C' },
  { name: 'Puma', slug: 'puma', logo: '', color: '#E42D2D' },
  { name: 'ASICS', slug: 'asics', logo: '', color: '#003DA5' },
  { name: 'Reebok', slug: 'reebok', logo: '', color: '#E41134' },
  { name: 'Converse', slug: 'converse', logo: '', color: '#1C1C1C' },
  { name: 'Vans', slug: 'vans', logo: '', color: '#C3002F' },
];

function generatePriceHistory(basePrice: number, days: number = 90): { date: string; price: number }[] {
  const history: { date: string; price: number }[] = [];
  const now = new Date();
  for (let i = days; i >= 0; i--) {
    const date = new Date(now);
    date.setDate(date.getDate() - i);
    const variation = (Math.random() - 0.4) * 30;
    const price = Math.round((basePrice + variation) * 100) / 100;
    history.push({
      date: date.toISOString().split('T')[0],
      price: Math.max(price, basePrice * 0.7),
    });
  }
  return history;
}

const allSizes = [36, 36.5, 37.5, 38, 38.5, 39, 40, 40.5, 41, 42, 42.5, 43, 44, 44.5, 45, 46];

function randomSizes(): number[] {
  return allSizes.filter(() => Math.random() > 0.3);
}

export const sneakers: Sneaker[] = [
  {
    id: '1', slug: 'nike-air-max-1-86-og-big-bubble',
    name: 'Air Max 1 \'86 OG Big Bubble', brand: 'Nike', brandSlug: 'nike',
    colorway: 'University Red/White', image: 'https://placehold.co/600x600/1a1a1a/00FF6A?text=AM1+86',
    lowestPrice: 139.99, originalPrice: 159.99,
    offers: [
      { shop: 'Patta', price: 149.99, originalPrice: 159.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'BSTN', price: 139.99, originalPrice: 159.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'Footlocker', price: 159.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'JD Sports', price: 154.99, url: '#', inStock: false, sizes: [] },
    ],
    sizes: allSizes, gender: 'unisex', releaseDate: '2025-12-01',
    trending: true, priceDrop: true,
    priceHistory: generatePriceHistory(155),
  },
  {
    id: '2', slug: 'adidas-samba-og-white-green',
    name: 'Samba OG', brand: 'Adidas', brandSlug: 'adidas',
    colorway: 'Cloud White/Green', image: 'https://placehold.co/600x600/1a1a1a/00FF6A?text=Samba+OG',
    lowestPrice: 99.99, originalPrice: 119.99,
    offers: [
      { shop: 'Zalando', price: 99.99, originalPrice: 119.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'About You', price: 109.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'BSTN', price: 104.99, originalPrice: 119.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'Sneaker District', price: 119.99, url: '#', inStock: true, sizes: randomSizes() },
    ],
    sizes: allSizes, gender: 'unisex', releaseDate: '2025-09-15',
    trending: true, priceDrop: true,
    priceHistory: generatePriceHistory(115),
  },
  {
    id: '3', slug: 'new-balance-990v6-grey',
    name: '990v6', brand: 'New Balance', brandSlug: 'new-balance',
    colorway: 'Grey/Silver', image: 'https://placehold.co/600x600/1a1a1a/00FF6A?text=990v6',
    lowestPrice: 199.99, originalPrice: 219.99,
    offers: [
      { shop: 'Patta', price: 219.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'BSTN', price: 199.99, originalPrice: 219.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'Solebox', price: 209.99, url: '#', inStock: true, sizes: randomSizes() },
    ],
    sizes: allSizes, gender: 'heren', releaseDate: '2025-10-20',
    trending: true, priceDrop: false,
    priceHistory: generatePriceHistory(215),
  },
  {
    id: '4', slug: 'nike-dunk-low-panda',
    name: 'Dunk Low Retro', brand: 'Nike', brandSlug: 'nike',
    colorway: 'Black/White (Panda)', image: 'https://placehold.co/600x600/1a1a1a/00FF6A?text=Dunk+Low',
    lowestPrice: 89.99, originalPrice: 119.99,
    offers: [
      { shop: 'Footlocker', price: 99.99, originalPrice: 119.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'JD Sports', price: 89.99, originalPrice: 119.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'Zalando', price: 94.99, originalPrice: 119.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'About You', price: 109.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'BSTN', price: 97.99, originalPrice: 119.99, url: '#', inStock: true, sizes: randomSizes() },
    ],
    sizes: allSizes, gender: 'unisex', releaseDate: '2025-06-01',
    trending: true, priceDrop: true,
    priceHistory: generatePriceHistory(110),
  },
  {
    id: '5', slug: 'asics-gel-kayano-14-silver',
    name: 'Gel-Kayano 14', brand: 'ASICS', brandSlug: 'asics',
    colorway: 'White/Pure Silver', image: 'https://placehold.co/600x600/1a1a1a/00FF6A?text=Kayano+14',
    lowestPrice: 134.99, originalPrice: 159.99,
    offers: [
      { shop: 'Solebox', price: 134.99, originalPrice: 159.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'BSTN', price: 139.99, originalPrice: 159.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'Patta', price: 159.99, url: '#', inStock: true, sizes: randomSizes() },
    ],
    sizes: allSizes, gender: 'unisex', releaseDate: '2025-11-10',
    trending: true, priceDrop: true,
    priceHistory: generatePriceHistory(152),
  },
  {
    id: '6', slug: 'adidas-gazelle-indoor-brown',
    name: 'Gazelle Indoor', brand: 'Adidas', brandSlug: 'adidas',
    colorway: 'Earth Strata/Brown', image: 'https://placehold.co/600x600/1a1a1a/00FF6A?text=Gazelle',
    lowestPrice: 109.99, originalPrice: 119.99,
    offers: [
      { shop: 'Sneaker District', price: 109.99, originalPrice: 119.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'Zalando', price: 119.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'About You', price: 114.99, url: '#', inStock: true, sizes: randomSizes() },
    ],
    sizes: allSizes, gender: 'unisex', releaseDate: '2025-08-22',
    trending: true, priceDrop: false,
    priceHistory: generatePriceHistory(118),
  },
  {
    id: '7', slug: 'nike-air-jordan-1-retro-high-chicago',
    name: 'Air Jordan 1 Retro High OG', brand: 'Nike', brandSlug: 'nike',
    colorway: 'Chicago/Lost & Found', image: 'https://placehold.co/600x600/1a1a1a/00FF6A?text=AJ1+Chi',
    lowestPrice: 169.99, originalPrice: 189.99,
    offers: [
      { shop: 'Patta', price: 189.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'BSTN', price: 169.99, originalPrice: 189.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'Footlocker', price: 179.99, url: '#', inStock: false, sizes: [] },
      { shop: 'JD Sports', price: 184.99, url: '#', inStock: true, sizes: randomSizes() },
    ],
    sizes: allSizes, gender: 'heren', releaseDate: '2025-07-15',
    trending: true, priceDrop: true,
    priceHistory: generatePriceHistory(185),
  },
  {
    id: '8', slug: 'new-balance-2002r-protection-pack',
    name: '2002R Protection Pack', brand: 'New Balance', brandSlug: 'new-balance',
    colorway: 'Phantom/Rain Cloud', image: 'https://placehold.co/600x600/1a1a1a/00FF6A?text=2002R',
    lowestPrice: 129.99, originalPrice: 159.99,
    offers: [
      { shop: 'BSTN', price: 129.99, originalPrice: 159.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'Solebox', price: 139.99, originalPrice: 159.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'Patta', price: 159.99, url: '#', inStock: true, sizes: randomSizes() },
    ],
    sizes: allSizes, gender: 'unisex', releaseDate: '2025-09-01',
    trending: true, priceDrop: true,
    priceHistory: generatePriceHistory(150),
  },
  {
    id: '9', slug: 'puma-suede-classic-black',
    name: 'Suede Classic XXI', brand: 'Puma', brandSlug: 'puma',
    colorway: 'Puma Black/White', image: 'https://placehold.co/600x600/1a1a1a/00FF6A?text=Suede',
    lowestPrice: 69.99, originalPrice: 89.99,
    offers: [
      { shop: 'Zalando', price: 69.99, originalPrice: 89.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'About You', price: 74.99, originalPrice: 89.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'JD Sports', price: 79.99, url: '#', inStock: true, sizes: randomSizes() },
    ],
    sizes: allSizes, gender: 'unisex', releaseDate: '2025-05-01',
    trending: false, priceDrop: true,
    priceHistory: generatePriceHistory(85),
  },
  {
    id: '10', slug: 'converse-chuck-70-hi-black',
    name: 'Chuck 70 Hi', brand: 'Converse', brandSlug: 'converse',
    colorway: 'Black/Egret', image: 'https://placehold.co/600x600/1a1a1a/00FF6A?text=Chuck+70',
    lowestPrice: 79.99, originalPrice: 94.99,
    offers: [
      { shop: 'Zalando', price: 79.99, originalPrice: 94.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'About You', price: 84.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'Footlocker', price: 94.99, url: '#', inStock: true, sizes: randomSizes() },
    ],
    sizes: allSizes, gender: 'unisex', releaseDate: '2025-04-01',
    trending: false, priceDrop: true,
    priceHistory: generatePriceHistory(90),
  },
  {
    id: '11', slug: 'vans-old-skool-black-white',
    name: 'Old Skool', brand: 'Vans', brandSlug: 'vans',
    colorway: 'Black/White', image: 'https://placehold.co/600x600/1a1a1a/00FF6A?text=Old+Skool',
    lowestPrice: 64.99, originalPrice: 84.99,
    offers: [
      { shop: 'Zalando', price: 64.99, originalPrice: 84.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'About You', price: 69.99, originalPrice: 84.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'Footlocker', price: 84.99, url: '#', inStock: true, sizes: randomSizes() },
    ],
    sizes: allSizes, gender: 'unisex', releaseDate: '2025-03-01',
    trending: false, priceDrop: true,
    priceHistory: generatePriceHistory(80),
  },
  {
    id: '12', slug: 'nike-air-force-1-07-white',
    name: 'Air Force 1 \'07', brand: 'Nike', brandSlug: 'nike',
    colorway: 'White/White', image: 'https://placehold.co/600x600/1a1a1a/00FF6A?text=AF1+07',
    lowestPrice: 99.99, originalPrice: 119.99,
    offers: [
      { shop: 'Footlocker', price: 99.99, originalPrice: 119.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'JD Sports', price: 109.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'Zalando', price: 104.99, originalPrice: 119.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'About You', price: 114.99, url: '#', inStock: true, sizes: randomSizes() },
    ],
    sizes: allSizes, gender: 'unisex', releaseDate: '2025-01-15',
    trending: false, priceDrop: true,
    priceHistory: generatePriceHistory(115),
  },
  {
    id: '13', slug: 'reebok-club-c-85-white',
    name: 'Club C 85', brand: 'Reebok', brandSlug: 'reebok',
    colorway: 'Chalk/Green', image: 'https://placehold.co/600x600/1a1a1a/00FF6A?text=Club+C',
    lowestPrice: 74.99, originalPrice: 99.99,
    offers: [
      { shop: 'Zalando', price: 74.99, originalPrice: 99.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'About You', price: 79.99, originalPrice: 99.99, url: '#', inStock: true, sizes: randomSizes() },
    ],
    sizes: allSizes, gender: 'unisex', releaseDate: '2025-02-01',
    trending: false, priceDrop: true,
    priceHistory: generatePriceHistory(95),
  },
  {
    id: '14', slug: 'nike-air-max-90-infrared',
    name: 'Air Max 90', brand: 'Nike', brandSlug: 'nike',
    colorway: 'White/Infrared', image: 'https://placehold.co/600x600/1a1a1a/00FF6A?text=AM90',
    lowestPrice: 119.99, originalPrice: 149.99,
    offers: [
      { shop: 'BSTN', price: 119.99, originalPrice: 149.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'Footlocker', price: 134.99, originalPrice: 149.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'JD Sports', price: 139.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'Patta', price: 149.99, url: '#', inStock: true, sizes: randomSizes() },
    ],
    sizes: allSizes, gender: 'heren', releaseDate: '2025-08-01',
    trending: false, priceDrop: true,
    priceHistory: generatePriceHistory(142),
  },
  {
    id: '15', slug: 'adidas-campus-00s-dark-green',
    name: 'Campus 00s', brand: 'Adidas', brandSlug: 'adidas',
    colorway: 'Dark Green/White', image: 'https://placehold.co/600x600/1a1a1a/00FF6A?text=Campus',
    lowestPrice: 94.99, originalPrice: 119.99,
    offers: [
      { shop: 'Sneaker District', price: 94.99, originalPrice: 119.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'BSTN', price: 99.99, originalPrice: 119.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'Zalando', price: 109.99, url: '#', inStock: true, sizes: randomSizes() },
    ],
    sizes: allSizes, gender: 'dames', releaseDate: '2025-07-01',
    trending: false, priceDrop: true,
    priceHistory: generatePriceHistory(115),
  },
  {
    id: '16', slug: 'new-balance-550-white-green',
    name: '550', brand: 'New Balance', brandSlug: 'new-balance',
    colorway: 'White/Green', image: 'https://placehold.co/600x600/1a1a1a/00FF6A?text=NB+550',
    lowestPrice: 109.99, originalPrice: 129.99,
    offers: [
      { shop: 'Patta', price: 129.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'BSTN', price: 109.99, originalPrice: 129.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'Solebox', price: 119.99, url: '#', inStock: true, sizes: randomSizes() },
    ],
    sizes: allSizes, gender: 'unisex', releaseDate: '2025-06-15',
    trending: false, priceDrop: true,
    priceHistory: generatePriceHistory(125),
  },
  {
    id: '17', slug: 'asics-gel-1130-silver',
    name: 'Gel-1130', brand: 'ASICS', brandSlug: 'asics',
    colorway: 'White/Clay Canyon', image: 'https://placehold.co/600x600/1a1a1a/00FF6A?text=1130',
    lowestPrice: 109.99, originalPrice: 129.99,
    offers: [
      { shop: 'Solebox', price: 109.99, originalPrice: 129.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'BSTN', price: 119.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'Sneaker District', price: 124.99, url: '#', inStock: true, sizes: randomSizes() },
    ],
    sizes: allSizes, gender: 'unisex', releaseDate: '2025-10-01',
    trending: false, priceDrop: false,
    priceHistory: generatePriceHistory(125),
  },
  {
    id: '18', slug: 'nike-air-max-plus-black-volt',
    name: 'Air Max Plus', brand: 'Nike', brandSlug: 'nike',
    colorway: 'Black/Volt', image: 'https://placehold.co/600x600/1a1a1a/00FF6A?text=AM+Plus',
    lowestPrice: 149.99, originalPrice: 179.99,
    offers: [
      { shop: 'Footlocker', price: 149.99, originalPrice: 179.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'JD Sports', price: 159.99, originalPrice: 179.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'BSTN', price: 169.99, url: '#', inStock: true, sizes: randomSizes() },
    ],
    sizes: allSizes, gender: 'heren', releaseDate: '2025-11-01',
    trending: false, priceDrop: true,
    priceHistory: generatePriceHistory(172),
  },
  {
    id: '19', slug: 'puma-speedcat-og-red',
    name: 'Speedcat OG', brand: 'Puma', brandSlug: 'puma',
    colorway: 'For All Time Red', image: 'https://placehold.co/600x600/1a1a1a/00FF6A?text=Speedcat',
    lowestPrice: 99.99, originalPrice: 119.99,
    offers: [
      { shop: 'BSTN', price: 99.99, originalPrice: 119.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'Zalando', price: 109.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'About You', price: 114.99, url: '#', inStock: true, sizes: randomSizes() },
    ],
    sizes: allSizes, gender: 'unisex', releaseDate: '2025-12-15',
    trending: false, priceDrop: true,
    priceHistory: generatePriceHistory(115),
  },
  {
    id: '20', slug: 'adidas-yeezy-boost-350-v2-onyx',
    name: 'Yeezy Boost 350 V2', brand: 'Adidas', brandSlug: 'adidas',
    colorway: 'Onyx', image: 'https://placehold.co/600x600/1a1a1a/00FF6A?text=Yeezy+350',
    lowestPrice: 229.99, originalPrice: 249.99,
    offers: [
      { shop: 'BSTN', price: 229.99, originalPrice: 249.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'Solebox', price: 239.99, url: '#', inStock: true, sizes: randomSizes() },
      { shop: 'Sneaker District', price: 249.99, url: '#', inStock: false, sizes: [] },
    ],
    sizes: allSizes, gender: 'unisex', releaseDate: '2025-10-15',
    trending: false, priceDrop: false,
    priceHistory: generatePriceHistory(245),
  },
];

export function getSneakerBySlug(slug: string): Sneaker | undefined {
  return sneakers.find(s => s.slug === slug);
}

export function getSneakersByBrand(brandSlug: string): Sneaker[] {
  return sneakers.filter(s => s.brandSlug === brandSlug);
}

export function getTrendingSneakers(): Sneaker[] {
  return sneakers.filter(s => s.trending);
}

export function getPriceDrops(): Sneaker[] {
  return sneakers.filter(s => s.priceDrop).sort((a, b) => {
    const aDiscount = ((a.originalPrice - a.lowestPrice) / a.originalPrice) * 100;
    const bDiscount = ((b.originalPrice - b.lowestPrice) / b.originalPrice) * 100;
    return bDiscount - aDiscount;
  });
}

export function getDiscountPercent(sneaker: Sneaker): number {
  return Math.round(((sneaker.originalPrice - sneaker.lowestPrice) / sneaker.originalPrice) * 100);
}

export function getBrandBySlug(slug: string): Brand | undefined {
  return brands.find(b => b.slug === slug);
}
