import request from '@/utils/request'

// 获取公众号授权链接（前端新页面跳转）
export function getAccount(query) {
  let { id, ...params } = query
  return request({
    url: '/mp-operation/mp/auth/' + id,
    method: 'get',
    params: params
  })
}

// 扫码成功后 在请求
export function authSuccess(query) {
  return request({
    url: `/mp-operation/mp/authSuccess?${query}`,
    method: 'get'
  })
}

// 获取公众号列表
export function getResourceList(data) {
  return request({
    url: `/erp/resource/list`,
    method: 'POST',
    data: data
  })
}

// 新增公众号
export function addResource(data) {
  return request({
    url: `/erp/resource`,
    method: 'POST',
    data: data
  })
}

// 修改公众号
export function editResource(data) {
  let {id, ...params} = data
  return request({
    url: `/erp/resource/${id}`,
    method: 'put',
    data: params
  })
}


// 获取公众号列表
export function getAccountList(data) {
  return request({
    url: `/mp-operation/mp/admin/admin/list`,
    method: 'POST',
    data: data
  })
}

// 新增公众号
export function addAccount(data) {
  let {id, ...params} = data
  return request({
    url: `/mp-operation/mp/admin/admin`,
    method: 'POST',
    data: params
  })
}

// 修改公众号
export function editAccount(data) {
  let {id, ...params} = data
  return request({
    url: `/mp-operation/mp/admin/admin/${id}`,
    method: 'put',
    data: params
  })
}

// 状态修改
export function editState(data) {
  let {id, ...params} = data
  return request({
    url: `/mp-operation/mp/admin/configStatus/${id}`,
    method: 'put',
    data: params
  })
}

// 搜索公众号列表
export function searchList(data) {
  return request({
    url: `/mp-operation/mp/admin/admin/search`,
    method: 'POST',
    data: data
  })
}
// 指派
export function assignResourceUser(data) {
  return request({
    url: `/erp/resource/configUserResourceByResource`,
    method: 'PUT',
    data: data
  })
}

// 指派
export function assignUser(data) {
  return request({
    url: `/mp-operation/mp/admin/configUserBatch`,
    method: 'PUT',
    data: data
  })
}

// 指派
export function configUser(data) {
  return request({
    url: `/mp-operation/mp/admin/configUser`,
    method: 'PUT',
    data: data
  })
}

// 删除
export function delResource(resourceIds) {
  return request({
    url: `/erp/resource/${resourceIds}`,
    method: 'DELETE'
  })
}

/**
 * 
 * 分组相关api
 * 
 */

// 新增分组
export function addGroup(data) {
  return request({
    url: `/erp/resourceGroup`,
    method: 'POST',
    data: data
  })
}

// 获取所有分组
export function getGroupAllList() {
  return request({
    url: `/erp/resourceGroup/all`
  })
}

// 删除分组
export function delGroup(id) {
  return request({
    url: `/erp/resourceGroup/${id}`,
    method: 'DELETE'
  })
}

// 修改分组
export function editGroup(params) {
  let { id, ...data} = params
  return request({
    url: `/erp/resourceGroup/${id}`,
    method: 'PUT',
    data
  })
}

// 修改公众号分组
export function editAccountGroup(params) {
  let { id, resourceGroupId } = params
  return request({
    url: `/erp/resource/configResourceGroup/${id}/${resourceGroupId}`,
    method: 'PUT'
  })
}

// 获取所有角色标签
export function getRoleAll() {
  return request({
    url: `/erp/resource/tag/all`
  })
}

// 刷新缓存
export function refreshCache() {
  return request({
    url: `/erp/resource/refreshCache`,
    method: "PUT"
  })
}


/**
 * 获取记录列表
 * @param {id, data} param0 data: {pageNum: 1, pageSize: 10} 
 * @returns 
 */
export function gitCutRecordList({id, ...data}) {
  return request({
    url: `/erp/resourceChangeRecord/list/${id}`,
    method: "POST",
    data
  })
}


/**
 * 插入记录
 * @param data param0 data: {
 *  lastChangeRecordId: 1, 上一条变更记录 id
 *  resourceId: 10 资源 id
 *  businessGroupId: 项目组 id
 *  operUserId 投手 id
 *  putUserId 期数 id
 *  periodId 书城 id
 *  platformId 书城 id
 *  platformAccountId 账号 id
 *  bookId 书 id
 *  putStatus 投放状态
 *  putChannel 投放渠道
 *  rechargeTemplate 充值模板
 *  beginTime 起始时间
 *  endTime 截止时间
 * } 
 * @returns 
 */
export function insertCutRecord(data) {
  return request({
    url: `/erp/resourceChangeRecord`,
    method: "POST",
    data
  })
}
/**
 * 修改记录
 * @param {*} data 同上
 * @returns 
 */
export function editCutRecord({id, ...data}) {
  return request({
    url: `/erp/resourceChangeRecord/${id}`,
    method: "PUT",
    data
  })
}

/**
 * 删除记录
 * @param {*} id 
 * @returns 
 */
export function delCutRecord(id) {
  return request({
    url: `/erp/resourceChangeRecord/${id}`,
    method: "DELETE"
  })
}

/**
 * 切书切平台
 * @param {*} 
 * resourceId
 * Long periodId;
 * Long platformId;
 * Long platformAccountId;
 * Long bookId;
 * String remark;
 * @returns 
 */
 export function cutBookPlatform({resourceId, ...data}) {
  return request({
    url: `/erp/resource/checkPlatform/${resourceId}`,
    method: "PUT",
    data
  })
}


export function checkTime({resourceId, beginTime}) {
  return request({
    url: `/erp/resourceChangeRecord/checkTime/${resourceId}/${beginTime}`,
    method: "PUT"
  })
}