import { Achievement, LeaderboardEntry } from '../types';

const MOCK_XP = {
  current: 4250,
  next: 5000,
  level: 12,
  rank: 420,
  totalEarned: 15400,
};

const MOCK_ACHIEVEMENTS: Achievement[] = [
  {
    id: 'a1',
    name: 'First Upload',
    description: 'Uploaded your first track',
    icon: '🎵',
    progress: 1,
    maxProgress: 1,
    xpReward: 50,
    category: 'creation',
  },
  {
    id: 'a2',
    name: 'Social Butterfly',
    description: 'Follow 10 users',
    icon: '🦋',
    progress: 10,
    maxProgress: 10,
    xpReward: 100,
    category: 'social',
  },
  {
    id: 'a3',
    name: 'Hit Maker',
    description: 'Get 1000 plays on a track',
    icon: '🔥',
    progress: 850,
    maxProgress: 1000,
    xpReward: 500,
    category: 'creation',
  },
  {
    id: 'a4',
    name: 'Collector',
    description: 'Buy 5 items from marketplace',
    icon: '💎',
    progress: 2,
    maxProgress: 5,
    xpReward: 300,
    category: 'collection',
  },
  {
    id: 'a5',
    name: 'Critique',
    description: 'Post 20 comments',
    icon: '💬',
    progress: 20,
    maxProgress: 20,
    xpReward: 150,
    category: 'community',
  },
  {
    id: 'a6',
    name: 'Influencer',
    description: 'Gain 100 followers',
    icon: '🌟',
    progress: 45,
    maxProgress: 100,
    xpReward: 1000,
    category: 'social',
  },
];

const MOCK_LEADERBOARD: LeaderboardEntry[] = [
  {
    rank: 1,
    userId: 'u4',
    username: 'Deadmau5',
    avatar: 'https://picsum.photos/id/100/100/100',
    level: 99,
    xp: 990000,
    trend: 0,
  },
  {
    rank: 2,
    userId: 'u2',
    username: 'Sarah Connor',
    avatar: 'https://picsum.photos/id/64/100/100',
    level: 45,
    xp: 45000,
    trend: 1,
  },
  {
    rank: 3,
    userId: 'u1',
    username: 'Cyber_Producer',
    avatar: 'https://picsum.photos/id/237/100/100',
    level: 12,
    xp: 4250,
    trend: -1,
  },
  {
    rank: 4,
    userId: 'u5',
    username: 'Neon_Pulse',
    avatar: 'https://picsum.photos/id/55/100/100',
    level: 10,
    xp: 3000,
    trend: 2,
  },
  {
    rank: 5,
    userId: 'u9',
    username: 'Newbie',
    avatar: 'https://picsum.photos/id/10/100/100',
    level: 2,
    xp: 500,
    trend: 0,
  },
];

export const gamificationService = {
  getUserXP: async (_userId: string) => {
    await new Promise((resolve) => setTimeout(resolve, 400));
    return MOCK_XP;
  },

  getAchievements: async (_userId: string) => {
    await new Promise((resolve) => setTimeout(resolve, 500));
    return MOCK_ACHIEVEMENTS;
  },

  getLeaderboard: async (period: 'weekly' | 'monthly' | 'all' = 'weekly') => {
    await new Promise((resolve) => setTimeout(resolve, 600));
    // Simulate slightly different data for periods
    if (period === 'monthly') {
      return MOCK_LEADERBOARD.map((e) => ({ ...e, xp: e.xp * 4 }));
    }
    return MOCK_LEADERBOARD;
  },

  claimReward: async (_achievementId: string) => {
    await new Promise((resolve) => setTimeout(resolve, 300));
    return { success: true, xpAdded: 50 };
  },
};
