import { apiClient, API_ENDPOINTS } from '@/config/api';
import type { Group } from '@/types/group';
import type { ChoreHistory } from '@/types/chore';

// 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[]> {
    const response = await apiClient.get(API_ENDPOINTS.GROUPS.BASE);
    return response.data;
  },

  async generateSchedule(groupId: string, data: { start_date: string; end_date: string; member_ids: number[] }): Promise<void> {
    await apiClient.post(API_ENDPOINTS.GROUPS.GENERATE_SCHEDULE(groupId), data);
  },

  async getGroupChoreHistory(groupId: string): Promise<ChoreHistory[]> {
    const response = await apiClient.get(API_ENDPOINTS.GROUPS.CHORE_HISTORY(groupId));
    return response.data;
  },

  // 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> { ... }
}
