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

const MOCK_GROUPS: SocialGroup[] = [
  {
    id: 'g1',
    name: 'Modular Synths Japan',
    members: 4200,
    isPrivate: false,
    userRole: 'member',
    description:
      'Patch cables and beep boops. The biggest modular community in Tokyo.',
    coverUrl: 'https://picsum.photos/id/10/800/400',
  },
  {
    id: 'g2',
    name: 'Ableton Live Pros',
    members: 12500,
    isPrivate: true,
    userRole: 'none',
    description:
      'Advanced techniques only. Sharing racks, max4live devices, and workflow hacks.',
    coverUrl: 'https://picsum.photos/id/20/800/400',
  },
  {
    id: 'g3',
    name: 'Lo-Fi Study Beats',
    members: 8900,
    isPrivate: false,
    userRole: 'none',
    description:
      'Chill vibes and beat making sessions. 24/7 radio and collaboration.',
    coverUrl: 'https://picsum.photos/id/30/800/400',
  },
  {
    id: 'g4',
    name: 'Sound Design 101',
    members: 1500,
    isPrivate: false,
    userRole: 'admin',
    description: 'Learning synthesis from scratch. Weekly challenges.',
    coverUrl: 'https://picsum.photos/id/40/800/400',
  },
  {
    id: 'g5',
    name: 'Mixing & Mastering',
    members: 32000,
    isPrivate: false,
    userRole: 'none',
    description: 'Get feedback on your mixdowns from industry professionals.',
    coverUrl: 'https://picsum.photos/id/50/800/400',
  },
];

export const groupService = {
  list: async () => {
    await new Promise((resolve) => setTimeout(resolve, 500));
    return { groups: MOCK_GROUPS };
  },

  get: async (id: string) => {
    await new Promise((resolve) => setTimeout(resolve, 300));
    const group = MOCK_GROUPS.find((g) => g.id === id) || MOCK_GROUPS[0];
    return {
      group,
      // Mock extra details usually fetched on detail view
      membersList: [
        {
          id: 'u1',
          username: 'Modular_King',
          avatar: 'https://picsum.photos/id/100/100',
          role: 'Admin',
        },
        {
          id: 'u2',
          username: 'Patch_Queen',
          avatar: 'https://picsum.photos/id/101/100',
          role: 'Mod',
        },
        {
          id: 'u3',
          username: 'Voltage_Ctrl',
          avatar: 'https://picsum.photos/id/102/100',
        },
      ],
      events: [
        {
          id: 'e1',
          title: 'Tokyo Synth Meetup',
          date: 'Oct 24, 2025',
          attendees: 150,
        },
        {
          id: 'e2',
          title: 'Online Patch Challenge',
          date: 'Nov 01, 2025',
          attendees: 400,
        },
      ],
    };
  },

  create: async (data: any) => {
    await new Promise((resolve) => setTimeout(resolve, 800));
    return {
      ...data,
      id: `g-${Date.now()}`,
      members: 1,
      userRole: 'admin',
    } as SocialGroup;
  },

  join: async (_id: string) => {
    await new Promise((resolve) => setTimeout(resolve, 400));
    return { success: true };
  },

  leave: async (_id: string) => {
    await new Promise((resolve) => setTimeout(resolve, 400));
    return { success: true };
  },
};
