import { paginate } from '@/services/mock/helpers'
import { register } from '@/services/mock/registry'
import { endpoints } from '@/services/api/endpoints'
import { adminTerms } from '@/services/mock/fixtures/admin-terms'

const STUDENT_ID = 5

// TermEnrollment rows for the mock student, each embedding its term. Two active
// (in-progress) terms and the rest completed, mirroring GET /student/my-terms.
const enrollments = adminTerms.map((term, i) => ({
  id: 10 + i,
  userId: STUDENT_ID,
  termId: term.id,
  status: i < 2 ? 'active' : 'completed',
  completedAt: i < 2 ? null : '2026-01-20T00:00:00.000Z',
  term,
}))

register('GET', endpoints.getStudentTerms, ({ query }) => {
  let list = enrollments
  if (query.status) list = list.filter((e) => e.status === String(query.status))
  const { data: items, meta } = paginate(list, query)
  return { success: true, message: 'OK', data: { items, meta } }
})

register('GET', endpoints.showStudentTerm, ({ params }) => {
  const found = enrollments.find((e) => String(e.termId) === String(params.id))
  return { success: true, message: 'OK', data: found || null }
})
