import type { PageResponse } from '#/api/http'

import { get, post } from '#/api/http'

export type ClassroomItem = {
  id: number | string
  name: string
}

export type ClassMonitorCurrent = {
  classId: number | string
  intervalMs: number
  monitoring: boolean
  sessionId: number | string
  startTime: string
  teacherId: number | string
}

export type ClassMonitorSnapshot = {
  avatar: string
  latestTs: number
  latestUrl: string
  staleSeconds: number
  studentId: number | string
  studentName: string
}

class ClassroomMonitorService {
  async getClassList() {
    return await get<PageResponse<ClassroomItem>>('/org/class/list', {
      current: 1,
      size: 25,
    })
  }

  async getCurrent(classId: number | string) {
    return await get<ClassMonitorCurrent>('/school/classMonitor/current', {
      classId,
    })
  }

  async getLatestSnapshots(classId: number | string) {
    return await get<ClassMonitorSnapshot[]>(
      '/school/classMonitor/latestSnapshots',
      { classId },
    )
  }

  async updateMonitorStatus(classId: number | string, status: 0 | 1) {
    return await post('/school/classMonitor/control', {
      classId,
      status,
    })
  }
}

export const classroomMonitorService = new ClassroomMonitorService()
