import axios, { type Response } from '@/utils/axios/axios';

/**
 * 得到课程房间列表 (教师端)
 */
export function getTeacherCourseRoomListAxios(): Promise<Response<RemoteCourseRoom[]>> {
  return axios.post<unknown, Response<RemoteCourseRoom[]>>(`/api/tutor/v1/tutorcourse/room/remote/list`);
}

/**
 * 得到课程房间列表 (学生端)
 */
export function getStudentCourseRoomListAxios(): Promise<Response<LocalCourseRoom[]>> {
  return axios.post<unknown, Response<LocalCourseRoom[]>>(`/api/tutor/v1/tutorcourse/room/local/list`);
}

/**
 * 得到 token
 */
export function getMeetingTokenAxios(channelName: string, uid: number): Promise<Response<MeetingToken>> {
  return axios.get<unknown, Response<MeetingToken>>(`${import.meta.env.VITE_MEETING_BASE_URL}/meeting/get-token/${channelName}/${uid}`);
}

/**
 * 获取房间黑名单（返回包含短 UID 和名称的数组）
 */
export function getBlacklistAxios(roomId: string): Promise<Response<BlacklistItem[]>> {
  return axios.get<unknown, Response<BlacklistItem[]>>(`${import.meta.env.VITE_MEETING_BASE_URL}/meeting/blacklist/${roomId}`);
}

/**
 * 从黑名单移除指定短 UID
 */
export function removeFromBlacklistAxios(roomId: string, shortUid: number): Promise<Response<boolean>> {
  return axios.delete<unknown, Response<boolean>>(`${import.meta.env.VITE_MEETING_BASE_URL}/meeting/blacklist/${roomId}/${shortUid}`);
}

/**
 * 黑名单用户项（包含短 UID 和名称)
 */
export interface BlacklistItem {
  /** 短 UID */
  shortUid: number;
  /** 用户名称 */
  userName: string;
}

export interface ReqMeetingToken {
  channelName: string;
  uid: number;
}

export interface MeetingToken {
  /** 声网应用的 appid */
  appid: string;
  /** Token */
  rtcToken: string;
  /** 实际过期时间戳（毫秒） */
  expiresAt: number;
}

export interface LocalCourseRoom {
  /** 课程房间ID */
  id: number;
  /** 课程房间名称 */
  name: string;
  /** 老师名称 */
  teacher: string;
  /** 课程房间状态 0 未开课 1 已开课 */
  status: 0 | 1;
  /** 开始时间 */
  startTime: string;
  /** 结束时间 */
  endTime: string;
}

export interface RemoteCourseRoom {
  /** 课程房间ID */
  id: number;
  /** 课程房间名称 */
  name: string;
  /** 老师名称 */
  teacher: string;
  /** 课程房间状态 0 未开课 1 已开课 */
  status: 0 | 1;
  /** 开始时间 */
  startTime: string;
  /** 结束时间 */
  endTime: string;
}
