import PushSet from '@/api/setting-center/PushSet'

class PushSetApi {
  constructor() {
    this.api = new PushSet()
  }

  cleanApp(data) {
    const d = data
    const result = {
      pushPlatform: d.pushPlatform,
      mobAppKey: d.mobAppKey,
      mobAppSecret: d.mobAppSecret,
      huaWeiAppId: d.huaWeiAppId,
      meiZuAppId: d.meiZuAppId,
      meiZuAppKey: d.meiZuAppKey,
      xiaoMiAppId: d.xiaoMiAppId,
      xiaoMiAppkey: d.xiaoMiAppkey,
      vivoAppId: d.vivoAppId,
      vivoAppKey: d.vivoAppKey,
      oppoAppId: d.oppoAppId,
      oppoAppKey: d.oppoAppKey,
      isOfficialPush: d.isOfficialPush
    }
    return result
  }

  loadForApp() {
    const l = this.api.loadByName('appPush')
    return l.then(res => {
      const data = res.data
      // return _.cloneDeep(data)
      return this.cleanApp(data)
    })
  }

  cleanMsg(data) {
    const d = data
    const result = {
      publicSmsCount: d.publicSmsCount,
      saleSmsCount: d.saleSmsCount,
      smsEmptyTipsNum: d.smsEmptyTipsNum,
      smsIsUnionTips: d.smsIsUnionTips,
      smsIsUseSmsPush: d.smsIsUseSmsPush,
      smsPushAppKey: d.smsPushAppKey,
      smsPushAppSecret: d.smsPushAppSecret,
      smsPushSign: d.smsPushSign,
      smsTipsPhone: d.smsTipsPhone
    }
    return result
  }

  loadForMsg() {
    const l = this.api.loadByName('smsPush')
    return l.then(res => {
      const data = res.data
      // return _.cloneDeep(data)
      return this.cleanMsg(data)
    })
  }

  // 提交数据
  updataByName(name, data) {
    // log(data, 'in updata')
    const d = JSON.stringify(data)
    const u = this.api.updataByName(name, d)
    return u
  }
}

const pushSetApi = new PushSetApi()

export default pushSetApi
