import flyio from "../flyio";
import {ApiResponse, ApiResponseList} from "@/types";
import {
    BatchEntity,
    ScoreRank, UniversityFilter,
    VoluntaryData, VoluntaryDto, VoluntaryEntity,
    VoluntaryHeaderResponse,
    VoluntaryMajor,
    VoluntaryRecommend
} from "@/types/vhs";
import config from "@/config";
import { RankingSegmentItem, RankingSegmentScore, RankingSegmentScoreQueryDTO, RankingSegmentTableQueryDTO } from "@/types/career";


// 志愿填报  科目和分数要求
export function getVoluntaryData(params: any) {
    return flyio.get('/front/syzy/zytb/getVoluntaryData', params) as Promise<ApiResponse<VoluntaryData>>
}


// 志愿填报  位次
export function getRankByScore(params: any) {
    return flyio.get('/front/syzy/yfyd/getRankByScore', params) as Promise<ApiResponse<ScoreRank>>
}

// 志愿填报  01.填报批次
export function zytbBatches(params: any) {
    return flyio.get('/front/syzy/zytb/batches', params) as Promise<ApiResponseList<BatchEntity>>
}

// 获取推荐志愿表头
export function getVoluntaryHeaders(params: any) {
    return flyio.get('/front/syzy/zytb/getVoluntaryHeaders', params) as Promise<VoluntaryHeaderResponse>
}

// 志愿填报  志愿组
export function getRecommendVoluntary(data: any, params: any) {
    return flyio.post('/front/syzy/zytb/getRecommendVoluntary', data, {params}) as Promise<ApiResponseList<VoluntaryRecommend>>
}

// 志愿填报  专业
export function getVoluntaryMarjors(data: any) {
    return flyio.post('/front/syzy/zytb/getVoluntaryMarjors', data) as Promise<ApiResponse<VoluntaryMajor[]>>
}


// 志愿填报  04.志愿保存
export function saveZhiyuan(data: VoluntaryDto) {
    return flyio.post('/front/syzy/zytb/save', data) as Promise<ApiResponse<number>>
}

// 获取志愿明细
export function getZhiyuanDetail(wishResId: number) {
    return flyio.get('/front/syzy/zytb/recordDetail', {wishResId}) as Promise<ApiResponse<VoluntaryEntity>>
}

// 填报批次  筛选条件
export function universityFilters(params: any) {
    return flyio.get('/front/syzy/zytb/university/filters', params) as Promise<ApiResponse<UniversityFilter>>
}


// 查询我的志愿表
export function selectZytbRecord(params: any) {
    return flyio.get(`/front/syzy/zytb/record`, params) as Promise<ApiResponseList<VoluntaryEntity>>
}

/**
 * 删除我的志愿表
 * @param params
 */
export function delZytbRecord(params: any) {
    return flyio.get(`/front/syzy/zytb/record/del`, params) as Promise<ApiResponse<boolean>>
}

/* download voluntary simulated excel */
export function downloadRecommendReport(params: any) {
    return flyio.get(`/front/syzy/zytb/export`, params, {responseType: 'arrayBuffer'}) as Promise<ApiResponse<string>>
}

export function getDownloadRecommendReportOptionsForWap2App(params: any) {
    return {
        url: config.serverBaseUrl + '/front/syzy/zytb/export',
        params
    }
}

export function getVoluntarySpecialProjectFilter(params: any) {
    // params = { year } // 缺省年份返回当前年份的专项选项
    // returns ['专项A', '专项B', '专项C', '不看专项']
    // getRecommendVoluntary 新增参数specialProjects: Array // 原来的参数specialProjectNation，specialProjectLocal不动
    return flyio.get(`/front/syzy/zytb/specialProjectFilter`, params) as Promise<ApiResponse<string[]>>
}

/**
 * 获取一分一段的省份列表
 * @returns 获取一分一段的省份列表
 */
export function getYfydLocations() {
  return flyio.get('/front/syzy/yfyd/locations') as Promise<ApiResponseList<string>>
}

/**
 * 获取一分一段的年份列表
 * @returns 获取一分一段的年份列表
 */
export function getYfydYears(location: string) {
  return flyio.get('/front/syzy/yfyd/years', { location }) as Promise<ApiResponseList<number>>
}

/**
 * 获取一分一段的分数列表
 * @param params 查询参数
 * @returns 获取一分一段的分数列表
 */
export function getYfydRankingList(params: RankingSegmentTableQueryDTO) {
  return flyio.get('/front/syzy/yfyd/list', params) as Promise<ApiResponseList<RankingSegmentItem>>
}

/**
 * 获取一分一段的分数详情
 * @param params 查询参数
 * @returns 获取一分一段的分数详情
 */
export function getYfydRankingScore(params: RankingSegmentScoreQueryDTO) {
  return flyio.get('/front/syzy/yfyd/getEquivalentScore', params) as Promise<ApiResponse<RankingSegmentScore>>
}