import { api } from './api'

// Define Group interface matching backend schema
export interface Group {
  id: number
  name: string
  description?: string
  created_at: string
  updated_at: string
  owner_id: number
  members: {
    id: number
    email: string
    role: 'owner' | 'member'
  }[]
}

export const groupService = {
  async getUserGroups(): Promise<Group[]> {
    try {
      const response = await api.get('/api/v1/groups')
      return response.data
    } catch (error) {
      console.error('Failed to fetch user groups:', error)
      throw error
    }
  },

  // Add other group-related service methods here, e.g.:
  // async getGroupDetails(groupId: number): Promise<Group> { ... }
  // async createGroup(groupData: any): Promise<Group> { ... }
  // async addUserToGroup(groupId: number, userId: number): Promise<void> { ... }
}
