import httpRequest from '@/utils/httpRequest'

const projectId = import.meta.env.VITE_PROJECT_ID

/**
 * 获取用户信息
 */
export function getUser(params = { learning_info: 1 }) {
  return httpRequest.get('/api/usercenter/v2/frontend/user/get-user-info', { params })
}

/**
 * 修改用户信息
 */
export function updateUser(data) {
  return httpRequest.post('/api/usercenter/user/update-user', data)
}

/**
 * 修改密码
 */
export function updatePassword(data) {
  return httpRequest.post('/api/usercenter/user/update-pwd', data)
}

/**
 * 发送验证码
 */
export function sendCode(data) {
  return httpRequest.post('/api/usercenter/user/send-code', data)
}

/**
 * 检验验证码
 */
export function checkCode(params) {
  return httpRequest.get('/api/usercenter/user/check-code', { params })
}

/**
 * 获取报名信息
 */
export function getApplication(params) {
  return httpRequest.get(`/api/enrollment/v1.0/application-materials/${projectId}`, { params })
}
/**
 * 获取报名信息
 */
export function updateApplication(data) {
  return httpRequest.post(`/api/enrollment/v1.0/application-materials/${projectId}/put`, data, {
    headers: { 'Content-Type': 'application/json' }
  })
}

/**
 * 获取报名审核状态
 */
export function getApplicationStatus() {
  return httpRequest.get(`/api/enrollment/v1.0/application-materials/profile/${projectId}`)
}

/**
 * 获取支付二维码
 */
export function getOrder(params) {
  return httpRequest.get(`/api/enrollment/v1.0/application-materials/payment-records/request/${projectId}/APPLICATION_FEE`, { params })
}

/**
 * 检查支付状态
 */
export function checkPay(id, params) {
  return httpRequest.get(`/api/enrollment/v1.0/application-materials/payment-records/check-status/${projectId}/APPLICATION_FEE/${id}`, { params })
}

/**
 * 写推荐信
 */
export function addLetter(userId, letterId, data) {
  return httpRequest.post(`/api/enrollment/v1.0/application-materials/reco-letters/submit/${projectId}/${userId}/${letterId}/put`, data, {
    headers: { 'Content-Type': 'application/json' }
  })
}

/**
 * 更换推荐人
 */
export function updateProvider(letterId, data) {
  return httpRequest.post(`/api/enrollment/v1.0/application-materials/reco-letters/change-provider/${projectId}/${letterId}/put`, data, {
    headers: { 'Content-Type': 'application/json' }
  })
}
/**
 * 再次邀请
 */
export function sendToProvider(letterId) {
  return httpRequest.get(`/api/enrollment/v1.0/application-materials/reco-letters/send-invitation-to-provider/${projectId}/${letterId}`)
}
/**
 * 退出登录
 */
export function logout() {
  return httpRequest.get('/api/passport/rest/logout')
}

/**
 * 更改附件状态
 */
export function changeFileStatus(userId, recordId, status) {
  return httpRequest.get(`/api/enrollment/v1.0/application-materials/attachments/change-status/${projectId}/${userId}/${recordId}`, { params: { status } })
}

/**
 * 修改用户信息
 */
export function getOpenId(data) {
  return httpRequest.post('/api/usercenter/v1/wechat/get-openid', data)
}

/**
 * 签名
 */
export function createSign(data) {
  return httpRequest.post('/api/usercenter/v1/sign/sign', data)
}

/**
 * 获取签名文档
 */
export function getSignDocument(params) {
  return httpRequest.get('/api/usercenter/v1/sign/document', { params })
}

/**
 * 提交留咨信息
 */
export function postNes(obj) {
  return httpRequest.post('/new-app/v1.0/applications', obj, {
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
  })
}
