import request from "../utils/request";
import { getRequestHostname } from "/src/utils"
import state from "/src/state"

/** 获取用户信息 */
export const studentQueryUserInfo = async () => {
  try {
    const requestHostname = getRequestHostname()
    if (requestHostname === "/api-teacher") {
      state.systemType = "teacher"
      const res = await request.get(`/teacher/queryUserInfo`);
      const data = res.data
      res.data = {
        instrumentId: "",
        phone:data.phone,
        clientType:"TEACHER",
        id:data.id,
        gender:""
      }
      return res
    } else if (requestHostname === "/api-web") {
      state.systemType = "web"
      let res
      if (state.isSchool) {
        res = await request.get("/schoolStaff/queryUserInfo", {
          requestType: "form",
        });
      } else {
        res = await request.get(`/employee/queryUserInfo`);
      }
      const data = res.data
      res.data = {
        instrumentId: "",
        specialInstrumentIds: [],
        phone:data.phone,
        clientType:"web",
        id:data.id,
        gender:""
      }
      return res
    } else {
      state.systemType = "student"
      const res = await request.get(`/student/queryUserInfo`);
      const data = res.data.student
      res.data = {
        instrumentId: res.data.instrumentId ? res.data.instrumentId.split(',')[0] : "",
        specialInstrumentIds: res.data.instrumentId ? res.data.instrumentId.split(',') : [],
        phone:data.phone,
        clientType:"STUDENT",
        id:data.id,
        gender:"",
        membershipEndTime: data.membershipEndTime
      }
      return res
    }
  } catch (error) {
    console.log(error)
  }
};

/** 获取曲谱详情 */
export const sysMusicScoreAccompanimentQueryPage = (sysMusicScoreId: string) => {
  return request.get("/musicSheet/detail/" + sysMusicScoreId);
};

/** 新增练习记录(包含评测) */
export const api_musicPracticeRecordSave = (data: any) => {
  return request.post("/musicPracticeRecord/save", { requestType: "json", data });
};
/** 添加作业记录(练习或评测) */
export const api_lessonTrainingSubmitTraining = (data: any, type?: string) => {
  const url = type === 'homeWork' ? `/studentCourseHomework/addStudentHomeworkRecord` : `/lessonExamination/submit`;
  if (type === 'homeWork') {
    return request.get(url + `?id=${data.id}`);
  } else {
    return request.post(url, { requestType: "json", data });
  }
};
/** 获取作业详情 */
export const api_lessonTrainingTrainingStudentDetail = (id: any, type: string) => {
  const url = type === 'homeWork' ? `/studentCourseHomework/homeworkDetail?id=${id}` : `/lessonExamination/getDetail?studentLessonExaminationDetailId=${id}`;
  return request.get(url);
};
/** 上传评测视频 */
export const api_musicPracticeRecordVideoUpload = (data: any) => {
  return request.post(`/musicPracticeRecord/videoUpload`, {
    data,
    requestType: "json",
  });
};

/** 提交意见反馈 */
export const sysSuggestionAdd = (data: any) => {
  return request.post("/suggestion/add", { data });
};

/** 获取评测报告 */
export const api_musicPracticeRecordDetail = (recordId: string) => {
  return request.get("/musicPracticeRecord/detail/" + recordId);
};

/** 获取声部 */
export const api_subjectList = (params: any) => {
  return request.post("/subject/list", {
    data: params,
    requestType: "json",
  });
};

/** 获取乐器列表 */
export const api_musicalInstrumentList = (params: any) => {
  return request.post("/musicalInstrument/list", {
    data: params,
    requestType: "json",
  });
};

/** 获取曲谱列表 */
export const api_musicSheetPage = (data: any) => {
  return request.post("/musicSheet/page", {
    data,
    requestType: "json",
  });
};

/**
 * 获取声部列表
 */
export const getSubjectList = (data: any) => {
  return request.post("/subject/page", {
    data,
    requestType: "json",
  });
};

/**
 * 获取意见类型
 */
export const getSuggestionList = (params: any) => {
  return request.post("/sysSuggestionType/queryAll", {
    data: params,
    requestType: "json",
  });
};
