import { Track, User, Course } from '../types';

export const searchService = {
  global: async (query: string, _type?: string, _page = 1) => {
    await new Promise((resolve) => setTimeout(resolve, 600)); // Simulate latency

    // Mock Results
    const tracks: Track[] = [
      {
        id: 't1',
        title: 'Neon Nights',
        artist: 'Cyber_Producer',
        album: 'Night City',
        duration: '3:45',
        durationSec: 225,
        plays: 15200,
        likes: 450,
        coverUrl: 'https://picsum.photos/id/10/300/300',
        genre: 'Synthwave',
        status: 'ready',
      },
      {
        id: 't2',
        title: 'Digital Rain',
        artist: 'Glitch_Mob',
        album: 'System',
        duration: '4:10',
        durationSec: 250,
        plays: 8900,
        likes: 210,
        coverUrl: 'https://picsum.photos/id/20/300/300',
        genre: 'Glitch',
        status: 'ready',
      },
    ].filter((t) =>
      t.title.toLowerCase().includes(query.toLowerCase()),
    ) as unknown as Track[];

    const users: User[] = [
      {
        id: 'u1',
        username: 'Cyber_Producer',
        fullName: 'Alex Mercer',
        avatar: 'https://picsum.photos/id/237/200/200',
        roles: ['PRODUCER'],
        status: 'online' as const,
        email: '',
        joinDate: '',
        tier: 'Pro' as const,
        bio: '',
        stats: { followers: 1200, following: 20, tracks: 10, plays: 5000 },
      },
      {
        id: 'u2',
        username: 'SynthLord',
        fullName: 'Sarah C',
        avatar: 'https://picsum.photos/id/64/200/200',
        roles: ['ARTIST'],
        status: 'offline' as const,
        email: '',
        joinDate: '',
        tier: 'Free' as const,
        bio: '',
        stats: { followers: 500, following: 10, tracks: 5, plays: 200 },
      },
    ].filter((u) =>
      u.username.toLowerCase().includes(query.toLowerCase()),
    ) as unknown as User[];

    const courses: Course[] = [
      {
        id: 'c1',
        title: 'Synthwave Masterclass',
        instructor: 'Neon Pulse',
        level: 'Advanced' as const,
        duration: '4h',
        thumbnailUrl: 'https://picsum.photos/id/100/400/250',
        progress: 0,
        studentCount: 120,
        rating: 4.8,
      },
    ].filter((c) => c.title.toLowerCase().includes(query.toLowerCase()));

    return {
      tracks,
      users,
      courses,
      playlists: [],
      total: tracks.length + users.length + courses.length,
    };
  },
};
