import request from '@/utils/request'



/**
 * 查询销售易账号列表
 */
export function listXsyAccount(query) {
  return request({
    url: '/xsy/account/company/list',
    method: 'get',
    params: query
  })
}

/**
 * 查询销售易账号详情
 */
export function getXsyAccount(id) {
  return request({
    url: '/xsy/account/get/' + id,
    method: 'get'
  })
}

/**
 * 新增销售易账号
 */
export function addXsyAccount(data) {
  return request({
    url: '/xsy/account/add',
    method: 'post',
    data: data
  })
}

/**
 * 修改销售易账号
 */
export function updateXsyAccount(data) {
  return request({
    url: '/xsy/account/update',
    method: 'post',
    data: data
  })
}

/**
 * 删除销售易账号
 */
export function delXsyAccount(id) {
  return request({
    url: '/xsy/account/delete/' + id,
    method: 'post'
  })
}

/**
 * 启用/禁用销售易账号
 */
export function updateXsyAccountStatus(id, status) {
  return request({
    url: '/xsy/account/status',
    method: 'post',
    params: {
      id: id,
      status: status
    }
  })
}

/**
 * 获取授权地址
 */
export function getXsyAuthUrl(accountId) {
  return request({
    url: '/xsy/account/authUrl/' + accountId,
    method: 'get'
  })
}



/**
 * 绑定销售易账号
 */
export function bindXsyAccount(data) {
  return request({
    url: '/xsy/bind/bind',
    method: 'post',
    data: data
  })
}

export function unbindXsyAccount(data) {
  return request({
    url: '/xsy/bind/unbind',
    method: 'post',
    data: data
  })
}

/**
 * 查询绑定关系
 */
export function getXsyBind(companyUserId) {
  return request({
    url: '/xsy/bind/get',
    method: 'get',
    params: {
      companyUserId: companyUserId
    }
  })
}



/**
 * 获取授权URL（新接口）
 */
export function getXsyOauthUrl(accountId) {
  return request({
    url: '/xiaoShouYi/New/auth/url/' + accountId,
    method: 'get'
  })
}



/**
 * 生成素材追踪链接
 */
export function generateXsyLink(companyUserId, data) {
  return request({
    url: '/xiaoShouYi/New/generateLink',
    method: 'post',
    params: {
      companyUserId: companyUserId
    },
    data: data
  })
}

/**
 * 发送确认
 */
export function sendXsyConfirm(companyUserId, forwardId, forwardType) {
  return request({
    url: '/xiaoShouYi/New/sendConfirm',
    method: 'post',
    params: {
      companyUserId: companyUserId,
      forwardId: forwardId,
      forwardType: forwardType
    }
  })
}

/**
 * 查询素材列表
 */
export function queryXsyMaterials(companyUserId, data) {
  return request({
    url: '/xiaoShouYi/New/materials/query',
    method: 'post',
    params: {
      companyUserId: companyUserId
    },
    data: data
  })
}

/**
 * 上传素材文件
 */
export function uploadXsyFile(companyUserId, file, isVideo) {
  const formData = new FormData()
  formData.append('file', file)
  formData.append('isVideo', isVideo == null ? false : isVideo)

  return request({
    url: '/xiaoShouYi/New/uploadFile?companyUserId=' + companyUserId,
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

/**
 * 创建素材
 */
export function createXsyMaterial(companyUserId, data) {
  return request({
    url: '/xiaoShouYi/New/createMaterial',
    method: 'post',
    params: {
      companyUserId: companyUserId
    },
    data: data
  })
}

/**
 * 上传并创建素材
 */
export function createXsyMaterialWithUpload(params) {
  const formData = new FormData()
  formData.append('companyUserId', params.companyUserId)
  formData.append('file', params.file)
  formData.append('isVideo', params.isVideo == null ? false : params.isVideo)
  formData.append('corpName', params.corpName)
  formData.append('materialType', params.materialType)
  formData.append('categoryName', params.categoryName)
  formData.append('title', params.title)

  return request({
    url: '/xiaoShouYi/New/createMaterialWithUpload',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

/**
 * 完整流程：生成链接并发送确认
 */
export function fullProcessXsy(companyUserId, data) {
  return request({
    url: '/xiaoShouYi/New/fullProcess',
    method: 'post',
    params: {
      companyUserId: companyUserId
    },
    data: data
  })
}
