import axios from '@/common/services/axios-instance'

class EntrustService {
  // 我的委托列表
  getEntrustList(params) {
    return axios({
      url: 'api/framework/v1/delegation/my-entrust',
      method: 'post',
      data: params,
    })
  }

  // 添加委托
  addEntrust(params) {
    return axios({
      url: 'api/framework/v1/delegation-manager/delegations',
      method: 'post',
      data: params,
    })
  }

  // 查看详情
  detailEntrust(params) {
    return axios({
      url: `api/framework/v1/delegation-manager/delegations/${params}`,
      method: 'get',
    }).then((res) => {
      return res.data
    })
  }

  // 我接受的委托列表
  getAcceptEntrusted(params) {
    return axios({
      url: 'api/framework/v1/delegation/my-entrusted',
      method: 'post',
      data: params,
    })
  }

  // 获取流程
  getFlowsList(params) {
    return axios({
      url: `api/framework/v1/flow-manage/flows/list-multi-app`,
      method: 'get',
      params,
    })
  }

  // 获取流程环节
  getFlowStep(params) {
    return axios({
      url: `api/framework/v1/flow-manage/flow-step-multi-app/${params.id}?appCode=${params.appCode}`,
      method: 'get',
    })
  }

  // 保存委托
  saveEntrust(params) {
    return axios.post('api/framework/v1/trust/changeTrust', params).then((res) => {
      return res.data
    })
  }

  // 获取委托信息
  getEntrust(account) {
    return axios.get(`api/framework/v1/trust/getTrustInfo/${account}`).then((res) => {
      return res.data
    })
  }

  // 通过id获取委托信息
  getEntrustById(id) {
    return axios.get(`api/framework/v1/trust/getTrustInfoById/${id}`).then((res) => {
      return res.data
    })
  }

  // 获取多应用列表
  getApps() {
    const params = {
      columns: ',id,appName,typeName,urlPc,urlMobile,creationTime',
      expressions: [],
      maxResults: -1,
      orderBy: 'creationTime asc',
      startPosition: 0,
    }

    return axios.post('api/framework/v1/navigator/appInfos/query', params).then((res) => {
      return res.data
    })
  }
}

export default new EntrustService()
