
import { reportClient } from '@/services/report'

/**
 * 报备客户
 * @param {*} userInfo 
 * @param {*} consultant 
 * @param {*} showToast 
 */
function report(person, consultant, showToast) {
  if (!person || !(person.tel || person.phone)) {
    return Promise.reject('用户手机号不存在');
  }

  if (!consultant || !consultant.id) {
    return Promise.reject('置业顾问信息不存在');
  }

  if (consultant.id == person.personId) {
    return Promise.resolve();
  }

  const realPhone = person.tel || person.phone
  const payload = {
    realtyConsultant: consultant.id, //报备人 置业顾问
    phone: realPhone,
    showToast,
  }

  return new Promise((resolve, reject) => {
    reportClient(payload).then(res => {
      resolve()
    }).catch(err => {
      console.error(err)
      reject(err.message || err)
    })
  })
}

export {
  report,
}
