import { cleanFilters } from '@/utils/clean-filters'
import { useMutation, useQuery } from '@tanstack/vue-query'
import {
  apiDownloadStudentCertificate,
  apiGetStudentCertificates,
} from '@/services/api/student-certificates'

export const studentCertificatesKeys = {
  all: ['student', 'certificates'],
  list: (filters, pagination) => ['student', 'certificates', 'list', filters, pagination],
}

export const useStudentCertificatesQuery = (filtersRef, paginationRef, options = {}) =>
  useQuery({
    queryKey: ['student', 'certificates', 'list', filtersRef, paginationRef],
    queryFn: () =>
      apiGetStudentCertificates({
        ...cleanFilters(filtersRef.value),
        ...paginationRef.value,
      }),
    ...options,
  })

export const useDownloadStudentCertificateMutation = () =>
  useMutation({ mutationFn: ({ id, format }) => apiDownloadStudentCertificate(id, format) })
