import flyio from "../flyio";
import { ApiResponse, ApiResponseList } from "@/types";
import { Major } from "@/types";

/**
 * 获取专业树
 * @param params 
 * @returns 
 */
export function getMajorTree(params: Major.MajorTreeQueryDTO) {
  return flyio.get('/front/major/getAllMajor', params) as Promise<ApiResponse<Major.MajorItem[]>>;
}

/**
 * 根据专业名称获取专业列表
 * @param params 
 * @returns 
 */
export function getMajorByName(params: Major.MajorTreeQueryDTO) {
  return flyio.get('/front/major/getMajorByName', params) as Promise<ApiResponse<Major.MajorItem[]>>;
}

/**
 * 根据专业代码获取专业概览
 * @param code 专业代码
 * @returns 
 */
export function getMajorOverviewByCode(code: string) {
  return flyio.get(`/front/major/getMajorOverviewByCode?code=${code}`) as Promise<ApiResponse<Major.MajorOverview>>;
}

/**
 * 根据专业代码获取开设院校
 * @param params 参数
 * @returns 
 */
export function getUniversityByMajorCode(params: Major.UniversityQueryDTO) {
  return flyio.get('/front/major/getUniversityByCode', params) as Promise<ApiResponseList<Major.University>>;
}

/**
 * 收藏专业
 * @param code 专业代码
 * @returns 
 */
export function collectMajor(code: string) {
  return flyio.get('/front/customer/marjors/add', { code }) as Promise<ApiResponse<any>>;
}

/**
 * 取消收藏专业
 * @param code 专业代码
 * @returns 
 */
export function cancelCollectMajor(code: string) {
  return flyio.get('/front/customer/marjors/remove', { code }) as Promise<ApiResponse<any>>;
}

/**
 * 获取收藏的专业
 * @param params 
 * @returns 
 */
export function getCollectedMajors(params: any) {
  return flyio.get('/front/customer/marjors/list', params) as Promise<ApiResponseList<Major.CollectedMajor>>;
}