import { request } from 'umi';
import { api } from '../api';
export type AddParams = {
  platformName: string;
  remark: string;
};
export type editbookParams = {
  id: number;
  platformId: number;
  author: string;
  bookName: string;
  protagonist: string;
  status: string;
  typeId: string;
  channel: string;
  wordCount: string;
  source: string;
  nodePrice: string;
  ratio: string;
  remark: string;
};
/**获取全部小说平台 */
export async function allBook() {
  return request(`${api}/erp/bookPlatform/all`);
}
/**获取书城下的账号**/
export async function listByPlatform(platformId: number) {
  console.log(platformId);
  return request(`${api}/erp/bookPlatformAccount/listByPlatform/${platformId}`);
}
/**搜索小说平台 */
export async function seekBook() {
  return request(`${api}/erp/bookPlatform/all`);
}
/** 删除vip小说 */
export async function delVipBookApi(periodId: number) {
  return request(`${api}/erp/period/${periodId}`, {
    method: 'DELETE',
  });
}
/** 编辑vip小说 */
export async function editVipBookApi(params: any) {
  let { accountId, ...data } = params;
  return request(`${api}/erp/bookPlatformAccount/${accountId}`, {
    method: 'PUT',
    data: data,
  });
}
/** 获取期数 */
export async function getPeriodAll() {
  return request(`${api}/erp/period/all`, {
    method: 'GET',
  });
}

/** 分页查询期数 */
export interface PeriodList {
  platformId: number; // 书城ID
  pageNum: number;
  pageSize: number;
  periodId?: number; // 期数ID
  account?: string; //账号搜索
  principalName?: string; // 开户名搜索
  status?: number; //账号状态  0：信息待完善、1：拉取中
}
export async function getPeriodListApi(params: PeriodList) {
  return request(`${api}/erp/bookPlatformAccount/pageByPlatform`, {
    method: 'GET',
    params,
  });
}

/**切换平台 */
export async function switchBook(params: {
  mpId: string;
  operType: string;
  remark: string;
  newBookName?: string;
  newPlatformId?: string;
}) {
  let { mpId, ...props } = params;
  return request(`${api}/system/mpOper/switchPlatform/${mpId}`, {
    method: 'PUT',
    data: props,
  });
}
/**操作日志 */
export async function logBook(params: { mpId: string }) {
  return request(`${api}/system/mpOper/operLog/${params.mpId}`);
}

/**投手配置 */
export async function switchPitcher(params: { mpId: string; userId: string }) {
  return request(`${api}/system/mp/configPutUser/${params.mpId}/${params.userId}`, {
    method: 'PUT',
  });
}

/**所有用户 */
export async function getUserAll() {
  return request(`${api}/system/user/all`);
}

/**编辑 */
export async function editSubmit(params: {
  mpId: string;
  account: string;
  managePhone: string;
  managePhoneNo: string;
  password: string;
  secret: string;
}) {
  let { mpId, ...props } = params;
  return request(`${api}/system/mp/modify/${mpId}`, {
    method: 'PUT',
    data: props,
  });
}

// 分页书籍
export async function getBookList(params: {
  bookName?: string;
  status?: string;
  platformId?: string;
  pageNum: number;
  pageSize: number;
}) {
  return request(`${api}/erp/book/list`, {
    method: 'POST',
    data: params,
  });
}
// 所有书籍

export async function getBookAll() {
  return request(`${api}/erp/book/all`, {
    method: 'GET',
  });
}

// 添加书籍
export async function addWorks(params: any) {
  return request(`${api}/erp/book`, {
    method: 'POST',
    data: params,
  });
}

// 修改书籍
export async function editWorks(params: any) {
  let { id, ...props } = params;
  return request(`${api}/erp/book/${id}`, {
    method: 'PUT',
    data: props,
  });
}

// 删除书籍
export async function deleteWorks(id: number) {
  return request(`${api}/erp/book/${id}`, {
    method: 'DELETE',
  });
}

// 所有小说分类
export async function getBooktypeList() {
  return request(`${api}/erp/bookType/all`, {
    method: 'GET',
  });
}

// 添加分类
export async function addBooktype(params: { name: string }) {
  return request(`${api}/erp/bookType`, {
    method: 'POST',
    data: params,
  });
}

// 编辑分类
export async function editBooktype(params: { id: number; name: string }) {
  let { id, ...data } = params;
  return request(`${api}/erp/bookType/${id}`, {
    method: 'PUT',
    data: data,
  });
}

// 删除类型
export async function deleteBooktype(id: number) {
  return request(`${api}/erp/bookType/${id}`, {
    method: 'DELETE',
  });
}

// 导入Excel
export async function importExcle(data: FormDataEntryValue) {
  return request(`${api}/erp/book/import`, {
    method: 'POST',
    body: data,
  });
}

// 导出
export async function exportExcle(data: any) {
  return request(`${api}/erp/book/export`, {
    method: 'POST',
    data: data,
    responseType: 'blob',
  });
}

// 模板下载
export async function downLoadTem() {
  return request(`${api}/erp/book/export/template`, {
    method: 'POST',
    data: {},
    responseType: 'blob',
  });
}

// 分页查询小说倍率
export async function bookRatioList(data: { bookId?: number; pageNum: number; pageSize: number }) {
  return request(`${api}/erp/bookRatio/list`, {
    method: 'POST',
    data,
  });
}

// 新增
export async function addRatio(data: {
  bookId: number;
  nodePrice: number;
  effectDay: string;
  overDay: string;
  type: string;
}) {
  return request(`${api}/erp/bookRatio`, {
    method: 'POST',
    data,
  });
}

// 分页查询小说倍率
export async function EditRatio(params: {
  id: number;
  bookId: number;
  nodePrice: number;
  ratio: number;
  effectDay: string;
  overDay: string;
}) {
  let { id, ...data } = params;
  return request(`${api}/erp/bookRatio/${id}`, {
    method: 'PUT',
    data,
  });
}

// 删除
export async function deleteRatio(id: number) {
  return request(`${api}/erp/bookRatio/${id}`, {
    method: 'DELETE',
  });
}

/**临时切换书城 */
export async function lins(params: any) {
  let { resourceId, ...param } = params;
  return request(`${api}/erp/resource/checkPlatform/${resourceId} `, {
    method: 'PUT',
    data: param,
  });
}
/**获取项目组*/
export async function businessGroup() {
  return request(`${api}/erp/businessGroup/all`);
}
/**切书记录*/
export async function resourceChangeRecord(params: any) {
  let { resourceId, ...param } = params;
  return request(`${api}/erp/resourceChangeRecord/list/${resourceId} `, {
    method: 'POST',
    data: param,
  });
}

/**
 * 插入记录
 * @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 interface insetCutProps {
  id?: number | null,
  beginTime?: string | null,
  endTime?: string | null,
  resourceId?: number,
  businessGroupId?: number,
  operUserId?: number,
  putUserId?: number,
  periodId?: number,
  platformId?: number,
  platformAccountId?: number,
  bookId?: number,
  putStatus?: string,
  putChannel?: string,
  rechargeTemplate?: string,
  lastChangeRecordId?: number
}
export async function insertCutRecordApi(data: insetCutProps) {
  return request(`${api}/erp/resourceChangeRecord`, {
    method: "POST",
    data
  })
}
/**
 * 修改记录
 * @param {*} data 同上
 * @returns 
 */
export interface editCutProps extends insetCutProps {
  id: number
}
export async function editCutRecordApi({ id, ...data }: editCutProps) {
  return request(`${api}/erp/resourceChangeRecord/${id}`, {
    method: "PUT",
    data
  })
}
/**
 * 删除记录
 * @param {*} id 
 * @returns 
 */
export async function delCutRecordApi(id: number) {
  return request(`${api}/erp/resourceChangeRecord/${id}`, {
    method: "DELETE"
  })
}

/**
 * 设置男频女频
 * @param param0 
 * @returns 
 */
export async function setChannelApi({ bookId, channel }: { bookId: number, channel: string | null }) {
  return request(`${api}/erp/book/configChannel/${bookId}/${channel}`, {
    method: "PUT"
  })
}

/**
 * 设置分类
 * @param param0 
 * @returns 
 */
 export async function setConfigTypeApi({ bookId, typeId }: { bookId: number, typeId: number | null }) {
  return request(`${api}/erp/book/configType/${bookId}/${typeId}`, {
    method: "PUT"
  })
}