import { api } from "@/lib/api-client";
import type { StudentLeaveRequest, StudentLeaveType, StudentLeaveCreateRequest } from "@/types/student-leave";
import type { PaginatedResponse, PaginationParams, ApiSuccessResponse } from "@/types";

export const studentLeaveService = {
  async listLeaves(params?: PaginationParams): Promise<PaginatedResponse<StudentLeaveRequest>> {
    return api.get<PaginatedResponse<StudentLeaveRequest>>("/student-leaves", params as Record<string, string | number | boolean | undefined>);
  },

  async createLeave(data: StudentLeaveCreateRequest): Promise<StudentLeaveRequest> {
    return api.post<StudentLeaveRequest>("/student-leaves", data);
  },

  async updateLeave(id: number, data: Partial<StudentLeaveCreateRequest>): Promise<StudentLeaveRequest> {
    return api.patch<StudentLeaveRequest>(`/student-leaves/${id}`, data);
  },

  async approveLeave(id: number): Promise<StudentLeaveRequest> {
    return api.post<StudentLeaveRequest>(`/student-leaves/${id}/approve`);
  },

  async rejectLeave(id: number): Promise<StudentLeaveRequest> {
    return api.post<StudentLeaveRequest>(`/student-leaves/${id}/reject`);
  },

  async listLeaveTypes(params?: PaginationParams): Promise<PaginatedResponse<StudentLeaveType>> {
    return api.get<PaginatedResponse<StudentLeaveType>>("/student-leave-types", params as Record<string, string | number | boolean | undefined>);
  },

  async createLeaveType(data: Pick<StudentLeaveType, "name">): Promise<StudentLeaveType> {
    return api.post<StudentLeaveType>("/student-leave-types", data);
  },
};
