import {request} from "@/api/request";

export interface Student {
  company_id: number
  avatar: string
  dep_ids: number[]
  email: string
  id_card: string
  name: string
  password: string
  phone_number: string
}

interface UserInfoData {
  dep_ids: number[]
  user: Student
}

interface setRoleTypeData {
  /** 当前超级管理员ID */
  auth_id: number
  /** 管理员权限，0 为员工，1为管理员，2为超级管理员 */
  role_type: number
}


export interface AddDepProps {
  id?: number | null
  name: string
  parent_id: number
  company_id: number
  sort: number
}

interface DepCurData {
  data: Curriculum[]
  total: number
}

export interface depCurProps {
  page: number
  size: number
  id: number
}

interface AddCurProps {
  course_id: number[]
  dep_id: number[]
}


interface DepListData {
  data: User[]
  department: Manage[]
}


export const ManageApi = {
  /** 添加学员 */
  addUser(data: Student) {
    return request('/api/v1/user/create', "POST", data)
  },
  userInfo(id: number) {
    return request<UserInfoData>(`/api/v1/user/${id}`, "GET")
  },
  putUser(id: number, data: Student) {
    return request(`/api/v1/user/front/${id}`, "PUT", data)
  },
  del(id: string) {
    return request(`/api/v1/user/${id}`, "DELETE")
  },
  /** 修改学员类型 */
  setRoleType(id: string, data: setRoleTypeData) {
    return request(`/api/v1/user/${id}`, "PUT", data)
  },
  /** 部门 */
  depList(dep_id: number | string) {
    return request<DepListData>('/api/v1/department/index?dep_id=' + dep_id, "GET")
  },
  addDep(data: AddDepProps) {
    return request('/api/v1/department/save', "POST", data)
  },
  putDep(id: string, name: string) {
    return request(`/api/v1/department/${id}`, "PUT", {name})
  },
  delDep(id: string) {
    return request(`/api/v1/department/${id}`, "DELETE")
  },
  /** 部门课程 */
  depCur(data: depCurProps) {
    return request<DepCurData>(`/api/v1/department/${data.id}/courses?page=${data.page}&size=${data.size}`, "GET")
  },
  /** 未添加课程 */
  optionalCur(dep_id: number, page: number, pageSize: number) {
    return request<Curriculum[]>(`/api/v1/course/choose/${dep_id}/index`, "GET", {page, pageSize})
  },
  addCur(data: AddCurProps) {
    return request('/api/v1/course/user', "POST", data)
  },
  buyAll() {
    return request<Curriculum[]>('/api/v1/course/buy/all', "GET")
  },
  buy(data_list: number[]) {
    return request(`/api/v1/course/buy?data_list=${data_list}`, "POST")
  },
}
