import { paginate } from '@/services/mock/helpers'
import { register } from '@/services/mock/registry'
import { endpoints } from '@/services/api/endpoints'
import {
  passedTerms,
  passedCourses,
  passedSessions,
} from '@/services/mock/fixtures/missionary-education'

register('GET', endpoints.getMissionaryPassedTerms, ({ query }) => {
  const { data: items, meta } = paginate(passedTerms, query)
  return { success: true, message: 'OK', data: { items, meta } }
})

register('GET', endpoints.getMissionaryPassedCourses, ({ query }) => {
  let list = passedCourses
  if (query.termId) list = list.filter((c) => String(c.termId) === String(query.termId))
  const { data: items, meta } = paginate(list, query)
  return { success: true, message: 'OK', data: { items, meta } }
})

register('GET', endpoints.getMissionaryPassedSessions, ({ query }) => {
  let list = passedSessions
  if (query.courseId) list = list.filter((s) => String(s.courseId) === String(query.courseId))
  const { data: items, meta } = paginate(list, query)
  return { success: true, message: 'OK', data: { items, meta } }
})
