import request from './fetcher/request'

// 房屋相关
export default {
  // 通过小区id获取房源
  houseListByEstateId (data) {
    return request.get('house/estate/houses', data)
  },
  // 获取房源列表
  houseList (data) {
    return request.get('house/list', data)
  },
  // house/agencyHouse
  fetchAgencyHouseList (data) {
    return request.get('house/agencyHouse', data)
  },
  // 房源详情
  houseDetail (house_id) {
    return request.get('house/detail', {
      house_id
    })
  },
  // 是否关注
  isHouseFocused ({ house_id, user_id}) {
    return request.get('user/focus', {
      house_id,
      user_id
    })
  },
  // 关注房源
  focusHouse ({house_id, is_valid}) {
    return request.post('user/focus/house/add', { house_id, is_valid })
  },
  // 取消关注
  cancleFocusHouse ({house_id}) {
    return request.get('user/focus/house/delete', { house_id, user_id: getApp().globalData.userinfo.user_id, token: getApp().globalData.token})
  },
  // 获取房源的经纪人列表
  getAgentByHouseId (house_id) {
    return request.get('agency/house/list', {
      house_id
    })
  },
  // 添加浏览记录
  addReadHistory ({ house_id }) {
    return request.post('user/read/house/add', { house_id })
  },
  // 增加分享记录
  addSharedHistory ({house_id, sale_type}) {
    return request.post('user/house/share/add', {house_id, sale_type})
  },
  // 根据场景获取经纪人
  getAgencyByScene (scene) {
    return request.get('house/getAgencyId', {scene_code: scene})
  },
  
  getRecommendHouse ({ page_num=1, page_size=10}) {
    return request.get('house/recommend', { page_num, page_size })
  },

  getHouseByScene (scene) {
    return request.get('house/getByScene', {scene_code: scene})
  },

  /* 向openApi发送数据
  ** @params user_id
  ** @params house_id
  ** @params room_id
  */
 postDataToOpen (data) {
   data.user_id = getApp().globalData.userinfo.user_id || ''
   return request.get('house/sendData', data)
 } 
}
