import { paginate } from '@/services/mock/helpers'
import { register } from '@/services/mock/registry'
import { endpoints } from '@/services/api/endpoints'
import { studentCertificates } from '@/services/mock/fixtures/student-certificates'

register('GET', endpoints.getStudentCertificates, ({ query }) =>
  paginate(studentCertificates, query)
)

register('GET', endpoints.downloadStudentCertificate, ({ params, query }) => {
  const cert = studentCertificates.find((c) => String(c.id) === String(params.id))
  const format = query?.format === 'jpg' ? 'jpg' : 'pdf'
  const url = format === 'jpg' ? cert?.jpgUrl : cert?.pdfUrl
  return { data: { id: params.id, format, url: url || '#' } }
})
