import request from '@/utils/request';
import { AxiosPromise } from 'axios';

export interface PostCandidateQuery extends PageQuery {
  postId?: string | number;
  keyword?: string;
  status?: string;
}

export interface PostCandidateVO {
  id: string | number;
  postId?: string | number;
  studentId?: string | number;
  evaluationId?: string | number;
  name?: string;
  gender?: string;
  phone?: string;
  status?: string;
  statusText?: string;
  statusType?: string;
  evaluateTime?: string;
  resumeFile?: string | number;
  remark?: string;
}

export interface PostCandidateHireForm {
  id: string | number;
  remark?: string;
  offerAttachment: string;
}

export interface PostCandidateStatusForm {
  id: string | number;
  status: string;
  remark?: string;
}

export function listPostCandidates(query: PostCandidateQuery): AxiosPromise<PostCandidateVO[]> {
  return request({
    url: '/main/postCandidate/list',
    method: 'get',
    params: query
  });
}

export function updatePostCandidateStatus(data: PostCandidateStatusForm) {
  return request({
    url: '/main/postCandidate/status',
    method: 'put',
    data
  });
}

export function hirePostCandidate(data: PostCandidateHireForm) {
  return request({
    url: '/main/postCandidate/hire',
    method: 'post',
    data
  });
}

export function downloadCandidateResume(candidateId: string | number) {
  return import('@/utils/request').then(({ default: req }) => {
    return req({
      url: `/main/postCandidate/resume/${candidateId}`,
      method: 'get',
      responseType: 'blob'
    });
  });
}
