import { api } from "@/lib/api-client";
import type {
  BulkCreateResult,
  CSVValidationReport,
  CredentialFilters,
  CredentialStatus,
} from "@/types";
import type { ApiSuccessResponse } from "@/types";

export const entityOnboardingService = {
  validateCsv: (file: File) => {
    const fd = new FormData();
    fd.append("file", file);
    return api.upload<CSVValidationReport>("/entity/students/validate-csv", fd);
  },

  bulkCreate: (payload: { validate_session_id?: string }) =>
    api.post<BulkCreateResult>("/entity/students/bulk-create", payload),

  sendCredentials: (studentIds: number[]) =>
    api.post<ApiSuccessResponse>("/entity/students/send-credentials", { user_ids: studentIds }),

  getCredentialStatuses: (
    filters?: CredentialFilters & { page?: number; limit?: number },
  ) =>
    api.get<{ data: CredentialStatus[]; pagination?: { total: number; page: number } }>(
      "/entity/students/credentials",
      filters as Record<string, string | number | boolean | undefined>,
    ),

  resendCredential: (studentId: number) =>
    api.post<ApiSuccessResponse>(`/entity/students/${studentId}/resend-credentials`),

  resendAllPending: () =>
    api.post<ApiSuccessResponse>("/entity/students/resend-all-pending"),
};
