import PaySet from '@/api/setting-center/PaySet'
import request from '@/utils/request'

class PaySetApi {
  constructor() {
    this.api = new PaySet()
  }

  clean(data) {
    const d = data
    const result = {
      alipayId: d.payAliAppId,
      privateKey: d.payAliPrivateKey,
      publicKey: d.payAliPublicKey,
      weChatId: d.payWxAppid,
      mchId: d.payWxMchId,
      weChatApiKey: d.payWxApiKey,
      apiclientCert: d.payWxClientCert,
      apiclientkey: d.payWxApiClientKey,
      aliKeyType: d.payAliKeyType,
      refundType: d.payRefundType,
      payList: d.payType,
      balanceImg: d.payBalanceImg,
      aliPayImg: d.payAliPayImg,
      wxPayImg: d.payWxPayImg
    }
    return result
  }

  load() {
    const l = this.api.load()
    return l.then(res => {
      return this.clean(res.data)
    })
  }

  saveData(data) {
    return request({
      url: '/setCenter/PaySet/payCenterSet',
      method: 'post',
      data
    })
  }
}

const paySetApi = new PaySetApi()

export default paySetApi
