import { baseUrl as baseurl, put, get, post } from './http'
export const baseUrl = baseurl

/* -------------------------20220801------------------------------ */
/**
 * 微信登录 获取token
 * @returns {Promise}
 */
export function zxclogin (code) {
  return get('/uiac/wx/login', {code})
}

/* ----------------------- 登录 注册 手机 ----------------------- */
/**
 * 微信登录 获取token
 * @returns {Promise}
 */
export function wxLogin (code) {
  return get('/uiac/wx/login', {code})
}

/**
 * 解密微信授权 获取用户信息
 * @returns {Promise}
 */
export function wxInfo (encryptedData, iv, rawData, signature, sessionKey) {
  return get('/uiac/wx/info', {encryptedData, iv, rawData, signature, sessionKey})
}

/**
 * 解密微信授权 获取用户手机
 * @returns {Promise}
 */
export function wxPhone (encryptedData, iv, sessionKey) {
  return get('/uiac/wx/phone', {encryptedData, iv, sessionKey})
}

/* ----------------------- 首页 ----------------------- */

/**
 * 横幅
 * @returns {Promise}
 */
export function wxBanner () {
  return post('/wx/banner/list')
}

/**
 * 查询首页模块开关
 * @returns {Promise}
 */
export function wxIndex () {
  return get('/wx/index/list')
}

/**
 * 首页数据
 * @returns {Promise}
 */
export function wxIndexData () {
  return get('/wx/index/module/article')
}

/* ----------------------- 搜索 ----------------------- */

/**
 * 获取热门搜索
 * @returns {Promise}
 */
export function getHotLog () {
  return get('/wx/search/hot-search-words')
}

/**
 * 搜索
 * @returns {Promise}
 */
export function search (data = '', start, limit = 10) {
  return post('/wx/search', {data, start, limit})
}

/* ----------------------- 消息页 ----------------------- */
/**
 * 获取个人没读消息
 * @returns {Promise}
 */
export function notifyPage (start, limit = 10) {
  return post('/wx/message-notify/page', {start, limit})
}

/**
 * 消息已读
 * @returns {Promise}
 */
export function read (id) {
  return put(`/wx/message-notify/${id}/read`)
}

/**
 * 造数据
 * @returns {Promise}
 */
export function mock () {
  return get('/wx/message-notify/mock')
}

/* ----------------------- 文章 ----------------------- */

/**
 * 文章详情
 * @returns {Promise}
 */
export function articleDetail (id) {
  return get(`/wx/article/${id}`)
}

/**
 * 文章收藏
 * @returns {Promise}
 */
export function articleCollect (id) {
  return post(`/wx/article/${id}/collect`)
}

/**
 * 标签列表
 * @returns {Promise}
 */
export function tagList (moduleType) {
  return post('/wx/tag/list', {data: {moduleType}})
}

/**
 * 文章列表
 * @returns {Promise}
 */
export function articleList (id) {
  return post(`/wx/article/page/doctor/${id}`)
}

/**
 * 文章类型列表
 * @returns {Promise}
 */
export function articleTypeList (type, tagId, start, limit = 10) {
  return post(`/wx/article/page/moduletype/${type}`, {data: {tagId}, start, limit})
}

/**
 * 文章推荐
 * @returns {Promise}
 */
export function articleRecommend (id) {
  return get(`/wx/article/${id}/recommend`)
}

/* ----------------------- 评论 ----------------------- */

/**
 * 获取评论
 * @returns {Promise}
 */
export function getComment (id, start, limit = 10) {
  return post(`/wx/comment/page/article/${id}`, {data: {}, start, limit})
}
/**
 * 点赞评论
 * @returns {Promise}
 */
export function startComment (id) {
  return post(`/wx/comment/${id}/like`)
}

/**
 * 评论
 * @returns {Promise}
 */
export function comment (articleId, content, parentId = '') {
  return post('/wx/comment', {articleId, content, parentId})
}

/* ----------------------- 医生 -----------------------

/**
 * 查询医生列表
 * @returns {Promise}
 */
export function getDoctorList (status, start = 1, limit = 10) {
  return post('/wx/doctor/page', {data: {status}, start, limit})
}

/**
 * 医生详情
 * @returns {Promise}
 */
export function doctorDetail (id) {
  return get(`/wx/doctor/${id}`)
}

/**
 * 医生文章
 * @returns {Promise}
 */
export function doctorArticle (id, start = 1, limit = 10) {
  return post(`/wx/article/page/doctor/${id}`, {data: {}, start, limit})
}

/* ----------------------- 个人中心 ----------------------- */

/**
 * 获取登录信息
 * @returns {Promise}
 */
export function myself () {
  return get('/uiac/myself')
}

/**
 * 获取账号初始化状态
 * @returns {Promise}
 */
export function membersStatus () {
  return get('/wx/members/init')
}

/**
 * 绑定手机号
 * @returns {Promise}
 */
export function bindPhone (jsCode, mobileNumber) {
  return post('/wx/members/bind-phonenumber', {data: {jsCode, mobileNumber}})
}

/**
 * 我的收藏
 * @returns {Promise}
 */
export function myCollect (start = 1, limit = 10) {
  return post('/wx/article/my-collect', {data: {}, start, limit})
}

/* ----------------------- 成长曲线 ----------------------- */

/**
 *  基础数据
 * @returns {Promise}
 */
export function babyInit () {
  return get('/wx/growth-curve/init')
}

/**
 * 添加宝宝
 * @returns {Promise}
 */
export function addBaby (birthday, gender, name) {
  return post('/wx/growth-curve/baby', {data: {birthday, gender, name}})
}

/**
 *  获取宝宝
 * @returns {Promise}
 */
export function getBaby () {
  return get('/wx/growth-curve/babys')
}

/**
 * 添加记录
 * @returns {Promise}
 */
export function addRecord (accountBabyId, head, height, weight, recordDate) {
  return post('/wx/growth-curve/record', {data: {accountBabyId, head, height, weight, recordDate}})
}

/**
 * 获取记录
 * @returns {Promise}
 */
export function getRecord (accountBabyId, ageRange) {
  return get(`/wx/growth-curve/records/${accountBabyId}/${ageRange}`)
}

/**
 * 获取专家指导
 * @returns {Promise}
 */
export function getGuide (accountBabyId) {
  return get(`/wx/growth-curve/expert-guidance/${accountBabyId}`)
}
