import api from 'src/config/api';

import {
  type CreateLearningCertificateRequest,
  type DeleteLearningCertificateParams,
  type LearningCertificateDTO,
  type ListLearningCertificatesParams,
  type ListLearningCertificatesResponse,
  type PatchLearningCertificateStatusParams,
  type UpdateLearningCertificateParams,
} from './types';

export const listLearningCertificates = (
  params: ListLearningCertificatesParams,
) =>
  api.get<ListLearningCertificatesResponse>('/learning-certificates', {
    params,
  });

export const getLearningCertificate = (certificateId: number) =>
  api.get<LearningCertificateDTO>(`/learning-certificates/${certificateId}`);

export const createLearningCertificate = (
  body: CreateLearningCertificateRequest,
) => api.post<LearningCertificateDTO>('/learning-certificates', body);

export const updateLearningCertificate = ({
  certificateId,
  data,
}: UpdateLearningCertificateParams) =>
  api.patch<LearningCertificateDTO>(
    `/learning-certificates/${certificateId}`,
    data,
  );

export const patchLearningCertificateStatus = ({
  certificateId,
  status,
}: PatchLearningCertificateStatusParams) =>
  api.patch<LearningCertificateDTO>(
    `/learning-certificates/${certificateId}/status`,
    { status },
  );

export const deleteLearningCertificate = ({
  certificateId,
}: DeleteLearningCertificateParams) =>
  api.delete<void>(`/learning-certificates/${certificateId}`);
