import { api } from "@/lib/api-client";
import type { Classroom, ClassroomCreateRequest, PaginatedResponse, PaginationParams, ApiSuccessResponse } from "@/types";

export interface ClassroomListParams extends PaginationParams {
  entity_id?: number;
}

export const classroomsService = {
  async list(params?: ClassroomListParams): Promise<PaginatedResponse<Classroom>> {
    return api.get<PaginatedResponse<Classroom>>("/groups", params as Record<string, string | number | boolean | undefined>);
  },

  async getById(id: number): Promise<Classroom> {
    return api.get<Classroom>(`/groups/${id}`);
  },

  async create(data: ClassroomCreateRequest): Promise<Classroom> {
    return api.post<Classroom>("/groups", data);
  },

  async delete(id: number): Promise<ApiSuccessResponse> {
    return api.delete<ApiSuccessResponse>(`/groups/${id}`);
  },

  async transfer(data: { student_ids: number[]; from_id: number; to_id: number }): Promise<ApiSuccessResponse> {
    return api.post<ApiSuccessResponse>("/groups/transfer", data);
  },

  async addMembers(id: number, userIds: number[]): Promise<ApiSuccessResponse> {
    return api.post<ApiSuccessResponse>(`/groups/${id}/members`, { user_ids: userIds });
  },

  async removeMembers(id: number, userIds: number[]): Promise<ApiSuccessResponse> {
    return api.post<ApiSuccessResponse>(`/groups/${id}/members/remove`, { user_ids: userIds });
  },
};
