import { api } from "@/lib/api-client";
import type { Gradebook, GradebookLine, GradingAssignment, GradingAssignmentCreateRequest } from "@/types/gradebook";
import type { PaginatedResponse, PaginationParams, ApiSuccessResponse } from "@/types";

export const gradebookService = {
  async listGradebooks(params?: PaginationParams): Promise<PaginatedResponse<Gradebook>> {
    return api.get<PaginatedResponse<Gradebook>>("/gradebooks", params as Record<string, string | number | boolean | undefined>);
  },

  async listGradebookLines(params?: PaginationParams): Promise<PaginatedResponse<GradebookLine>> {
    return api.get<PaginatedResponse<GradebookLine>>("/gradebook-lines", params as Record<string, string | number | boolean | undefined>);
  },

  async listGradingAssignments(params?: PaginationParams): Promise<PaginatedResponse<GradingAssignment>> {
    return api.get<PaginatedResponse<GradingAssignment>>("/grading-assignments", params as Record<string, string | number | boolean | undefined>);
  },

  async createGradingAssignment(data: GradingAssignmentCreateRequest): Promise<GradingAssignment> {
    return api.post<GradingAssignment>("/grading-assignments", data);
  },

  async updateGradingAssignment(id: number, data: Partial<GradingAssignmentCreateRequest>): Promise<GradingAssignment> {
    return api.patch<GradingAssignment>(`/grading-assignments/${id}`, data);
  },

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