import { AxiosPromise } from "axios";
import axios from "./config";

// NOTE: 暂时使用ts-ignore忽略module not exported的问题
// @ts-ignore
import {
  ILogitem,
  IUser,
  IList,
  IDeliveryBook,
  IOfficialSimple,
  IBookSearchResult,
  ADpushSimple,
  IOfficials,
  ADPlanItem,
  deliveryPlanItem,
  IPlatform,
  adPlanLog,
  adPlanCount,
  PlanBack,
  RegisterData,
  FinanceData,
  AdGroupData,
  AdgroupList,
  IUserAdmin,
  AccountPlanConfig,
  IGZHItem,
  OListItem,
  IDomainItem,
  IPBookItem,
} from "#/api";
import { any } from "vue-types";

/**
 * 登录
 * @param userData 用户信息
 */
export const doLogin = <T>(userData: T): AxiosPromise<IUser> => {
  return axios.post("/login", userData);
};

/**
 * 书籍搜素
 * @param key_word
 * @param page
 */
export const getDeliveryBookList = (
  query: Partial<{
    official_name: string;
    book_name: string;
    page: number;
  }> = { page: 1 }
): AxiosPromise<IList<IDeliveryBook>> => {
  return axios("/getUserDeliveryBooks", {
    params: query,
  });
};

/**
 * 获取公众号 - 无分页 用作于下拉
 */
export const getOfficialSimpleAccount = (): AxiosPromise<IOfficialSimple[]> => {
  return axios("/simpleUserOfficialAccounts");
};

/**
 * 通过书名搜索书籍
 * @param key_word
 * @param page
 */
export const getBooksByName = (
  key_word: string,
  page = 1
): AxiosPromise<IList<IBookSearchResult>> => {
  return axios("/searchBooks", { params: { key_word, page } });
};

/**
 * @description: 获取广告投放列表
 */
export const getAdPushList = (
  query: Partial<{
    email: string;
    account_name: string;
    account_id: string;
    advertiser_id: string;
    page: number;
  }> = { page: 1 }
): AxiosPromise<IList<ADpushSimple>> => {
  return axios("/ad/userAdAdvertisers", { params: query });
};

/**
 * 获取公众号列表
 * @param query
 */
export const getOfficialAccounts = (query: {
  official_name: string;
  platform: string;
  page: number;
  report_module: any;
  report_status: any;
  report_platform?: string;
}): AxiosPromise<IList<IOfficials>> => {
  return axios("/userOfficialAccounts", { params: query });
};

//橙子列表的获取
export const getOrangeProductListApi = (query: {
  app_name: string;
}): AxiosPromise<IList<OListItem>> => {
  return axios("/yuewenfx/getProductList", { params: query });
};
//橙子建站修改微信公众号
export const editOrangeWxApi = (query: {
  appName: string;
  alias: string;
  appflag: string;
}) => {
  return axios("/yuewenfx/editAppFlagsList", { params: query });
};
//橙子建站回传配置
export const upDateReportConfigApi = (query: {
  appflag: string;
  rate: string;
  condition: string;
  price: string;
}) => {
  return axios("/yuewenfx/updateReportConfig", { params: query });
};
//橙子建站回传日志

export const getOrangeLogListApi = (query: {
  guid?: string;
  start_time?: string;
  end_time?: string;
  appflag: string;
}): AxiosPromise<IList<ILogitem>> => {
  return axios("/yuewenfx/getYueWenFxReportLogList", { params: query });
};
// export const addDeliveryBook = (data: {
//   delivery_bid: string | number;
//   official_id: string | number;
//   platform: string;
// }) => {
//   return axios.post("/addDeliveryBook", data);
// };
//橙子建站强制回传
export const getforceReportApi = (data: {
  guid: string;
  paltform: string;
  reportType: string;
}) => {
  return axios.post("/yuewenfx/forceReport", data);
};

export const getOfficialOrangeApi = (query: {
  appflag: string;
  rate: string;
  condition: string;
}) => {
  return axios("api/yuewenfx/getProductList", { params: query });
};

/**
 * 获取公众号列表
 * @param query
 */
export const getADPlanlist = (
  query: Partial<{
    ad_id: string;
    advertiser_id: string;
    campaign_id: string;
    status: string;
    begin_date: any;
    end_date: any;
    cost_order: number;
    page: number;
  }> = { page: 1 }
): AxiosPromise<IList<ADPlanItem>> => {
  return axios("/ad/adData", { params: query });
};

/**
 * @description: 获取投放数据列表
 */
export const getDeliveryStatList = (
  query: Partial<{
    start_time: string;
    end_time: string;
    official_name: string;
    book_name: string;
    page: number;
    day_num: number;
  }> = { page: 1 }
): AxiosPromise<any> => {
  return axios("/delivery/stat", { params: query });
};

/*
 * 获取平台列表
 */
export const getPlatforms = (): AxiosPromise<IPlatform[]> => {
  return axios("/simplePlatforms");
};

/**
 * 添加投放书籍
 * @param data
 */
export const addDeliveryBook = (data: {
  delivery_bid: string | number;
  official_id: string | number;
  platform: string;
}) => {
  return axios.post("/addDeliveryBook", data);
};

/**
 * 退出登录
 */
export const logout = () => {
  return axios("/logout");
};

/**
 * 停止投放书籍
 * @param id 记录id
 */
export const onStopDeliveryBook = (id: number) => {
  return axios("/stopDeliveryBook", { params: { id } });
};

/**
 * 自定义列
 * @param null
 */
export const getCustomColumn = () => {
  return axios("/ad/adFields");
};

/**
 * @description: 获取更多投放数据
 */
export const getDeliveryMoreStatList = (
  query: Partial<{
    official_id: number;
    start_time: string;
    end_time: string;
    official_name: string;
    book_name: string;
    page: number;
  }> = { page: 1 }
): AxiosPromise<IList<any>> => {
  return axios("/delivery/moreStat", { params: query });
};

/* 广告授权
 * @param null
 */
export const getAdauth = () => {
  return axios("/oauth/accountGrant");
};

/* 广告预算修改
 * @param null
 */
export const adChangeMoney = (data: {
  ad_id: string | number;
  budget: string | number;
}) => {
  return axios.post("/ad/updateAdBudget", data);
};

/* 广告出价修改
 * @param null
 */
export const adChangeCrem = (data: {
  ad_id: string | number;
  bid: string | number;
}) => {
  return axios.post("/api/updateAdBid", data);
};

/* 修改广告状态
 * @param null
 */
export const statusChange = (data: {
  ad_id: string | number;
  status: string;
}) => {
  return axios.post("/ad/updateAdStatus", data);
};

/* 获取操作日志
 * @param null
 */
export const opertaroLog = (
  query: Partial<{
    begin_time: string;
    end_time: string;
    page: number;
    ad_id: string;
  }> = { page: 1 }
): AxiosPromise<IList<adPlanLog>> => {
  return axios("/ad/adOptLogs", { params: query });
};

/* 获取广告状态
 * @param null
 */
export const getAddStatus = (): AxiosPromise<any> => {
  return axios("/ad/adStatus");
};

//广告计划字段
export const getAdplanTable = (query: {
  field: string;
}): AxiosPromise<Array<{
  desc: string;
  name: string;
}>> => {
  return axios("/ad/adStatFields", { params: query });
};

//广告计划字段
export const getAdplanData = (query: {
  field: string;
  begin_date: string;
  end_date: string;
  ids: string;
  page: number;
}): AxiosPromise<any> => {
  return axios("/ad/adStats", { params: query });
};

//获取计划的回传配置
export const getAdBackPlan = (query: {
  ad_lid: string;
  back_platform: string;
}): AxiosPromise<any> => {
  return axios("/getReportConfig", { params: query });
};

//设置回传配置
export const setBackConfig = (data: {
  id: string | number;
  back_on: number;
  rate: number;
  condition: string;
  price: number;
  float_rate: string | number;
}) => {
  return axios.post("/setReportConfig", data);
};

/**
 * @description: 获取广告投放列表
 */
export const getRegisterData = (
  query: Partial<{
    ad_lid: number;
    back_platform: string;
    is_paid: number;
    show_all: number;
    page: number;
  }> = { page: 1 }
): AxiosPromise<IList<RegisterData>> => {
  return axios("/getAdMatchUsers", { params: query });
};

//强制回传
export const setMustUpback = (data: {
  uid: string | number;
  platform: string;
  report_type: string;
  report_platform?: string;
}) => {
  return axios.post("/forceReport", data);
};

//广告统计字段
export const getAdStatus = (): AxiosPromise<Array<{
  desc: string;
  name: string;
}>> => {
  return axios("/ad/adStatOptFields");
};

//广告统计tab
export const getDesignList = (query: {
  day_num: number;
}): AxiosPromise<Array<{
  desc: string;
  name: string;
}>> => {
  return axios("/delivery/getDeliveryStatFields", { params: query });
};

//财务数据
export const getFinanceList = (
  query: Partial<{
    start_ymd: string;
    end_ymd: string;
    page: number;
    advertiser_id: string;
  }> = { page: 1 }
): AxiosPromise<IList<FinanceData>> => {
  return axios("/ad/adFinanceStat", { params: query });
};

//广告组数据
export const getAdgroupList = (
  query: Partial<{
    advertiser_id: string;
    account_id: string;
    campaign_id: string;
    is_enable: any;
    begin_date: string;
    end_date: string;
    page: number;
    uids: string;
  }> = { page: 1 }
): AxiosPromise<IList<AdGroupData>> => {
  return axios("/ad/adCampaigns", { params: query });
};

//修改广告组状态
export const setGroupStatus = (data: {
  campaign_id: string | number;
  status: string | number;
}) => {
  return axios.post("/ad/updateCampaignStatus", data);
};

//广告组账户列表
export const getAdgroupData = (
  query: Partial<{
    advertiser_id: string | number;
    account_id: string | number;
    page: number;
    begin_date: string;
    end_date: string;
    uids: string;
  }> = { page: 1 }
): AxiosPromise<IList<AdgroupList>> => {
  return axios("/ad/adAdvertisers", { params: query });
};

//更新账户日预算
export const setGroupDay = (data: {
  advertiser_id: string | number;
  budget_mode: string;
  budget?: number | string;
}) => {
  return axios.post("/ad/updateAdvertiserBudget", data);
};

//获取自定义所有列
export const getCoustomClomuns = (): any => {
  return axios("/ad/getFields");
};

//设置站点回传比例
export const setChannelRate = (data: {
  rate: string | number;
  channel_id: string;
  report_platform?: string;
}) => {
  return axios.post("/setChannelConfig", data);
};

//保存自定义列
export const setCoustomClomuns = (data: any): any => {
  return axios.post("/ad/saveFields", { fields: data });
};

//获取组统计
export const ALLadGroupData = (
  query: Partial<{
    advertiser_id: string | number;
    campaign_id: string | number;
    end_date: string;
    begin_date: string;
    cost_order: number;
    uids: string;
  }>
) => {
  return axios("/ad/adCampaignSum", { params: query });
};

//获取🐖统计
export const ALLAcountGroupData = (
  query: Partial<{
    advertiser_id: string | number;
    campaign_id: string | number;
    begin_date: string;
    end_date: string;
    cost_order: number;
    uids: string;
  }>
) => {
  return axios("/ad/adAdvertiserSum", { params: query });
};

//获取广告计划汇总
export const getadDataSum = (
  query: Partial<{
    advertiser_id: string | number;
    campaign_id: string | number;
    ad_id: number;
    begin_date: string;
    end_date: string;
    cost_order: number;
    status: number | string;
  }>
) => {
  return axios("/ad/adSumData", { params: query });
};

//设置回传付费最低金额
export const setBackMinimum = (data: {
  advertiser_id: string;
  back_min_price: number | string;
}) => {
  return axios.post("/setAdAdvertiserBackMinPrice", data);
};

/* 修改广告状态
 * @param null
 */
export const statusAdChange = (data: {
  advertiser_id: string | number;
  is_enable: string | number;
}) => {
  return axios("/ad/updateAdvertiserStatus", { params: data });
};

/**
 * 获取权限用户列表
 * @returns
 */
export const getAuthorUser = (): AxiosPromise<any> => {
  return axios("/userInfo");
};

// 获取公众号回传配置
export const getOfficialBackConfig = (
  channel_id: number,
  report_platform?: string
): AxiosPromise<AccountPlanConfig> => {
  return axios("/channel/reportConfig", {
    params: { channel_id, report_platform },
  });
};

// 保存公众号回传配置
export const setOfficialBackConfig = (data: any) => {
  return axios.post("/channel/setReportConfig", data);
};

// 切换公众号回传方式
export const onUpdateOfficialReportType = (
  channel_id: number,
  report_module: string,
  report_platform?: string
) => {
  return axios.post("/channel/switchReportModule", {
    channel_id,
    report_module,
    report_platform,
  });
};

/**
 * 获取落地页列表
 * @returns
 */
export const getLandingPageList = (data: {
  page: number | 1;
  title?: string;
  link_source?: string;
  gzh_name?: string;
  start_time?: string;
  end_time?: string;
  status?: number;
}) => {
  return axios("/landingPage/list", { params: data });
};

/**
 * 删除落地页
 * @returns
 */
export const landingDelete = (data: { id: string | number }) => {
  return axios("/landingPage/delete", { params: data });
};

/**
 * 落地页 创建落地页
 * @returns
 */
export const landingAdd = (data: any) => {
  return axios.post("/landingPage/add", data);
};

/**
 * 落地页书籍列表
 * @returns
 */
export const landingBook = (data: {
  book_name?: string;
  official_name?: string;
}) => {
  return axios("/landingPage/books", { params: data });
};

/**
 * 生成落地页
 * @returns
 */
export const setLandingBook = (data: any) => {
  return axios.post("/landingPage/setLink", data);
};

/**
 * 落地页章节列表
 * @returns
 */
export const landingCharpter = (data: { bid?: string }) => {
  return axios("/landingPage/chapters", { params: data });
};

/**
 * 落地页我得图片
 * @returns
 */
export const landingMypic = (data: any) => {
  return axios("/landingPage/myDocuments", { params: data });
};

/**
 * 落地页保存封面
 * @returns
 */
export const landingSaveMypic = (url: string) => {
  return axios("/landingPage/uploadDocument", { params: { link: url } });
};

/**
 * 落地页 编辑
 * @returns
 */
export const landingEdit = (data: any) => {
  return axios.post("/landingPage/edit", data);
};

/**
 * 落地页 提交审核
 * @returns
 */
export const landingSubmit = (data: { id: string | number }) => {
  return axios("/landingPage/submit", { params: data });
};

/*
 * 获取落地页公众号列表
 * @returns
 */
export const getLandingOfficials = (): AxiosPromise<IList<IGZHItem>> => {
  return axios("/landingPage/getGzh");
};

/**
 * 获取落地页域名列表
 * @returns
 */
export const getLandingDomains = (): AxiosPromise<IList<IDomainItem>> => {
  return axios("/landingPage/domain");
};

/**
 * 获取落地页详情
 * @returns
 */
export const getLandingInfo = (id: string): AxiosPromise<any> => {
  return axios("/landingPage/info", { params: { id } });
};

/**
 * 获取落地页推广书籍列表
 * @param official_name
 * @param book_name
 * @returns
 */
export const getLandingBooks = (
  official_name?: string,
  book_name?: string
): AxiosPromise<IList<IPBookItem>> => {
  return axios("/landingPage/books", {
    params: {
      official_name,
      book_name,
      page_size: 999,
    },
  });
};

/**
 * 获取封面列表
 * @param type
 * @param category
 * @returns
 */
export const getLandingPic = (type?: any, category?: any, page?: any): any => {
  return axios("/landingPage/documents", {
    params: {
      type,
      category,
      page,
    },
  });
};

/**
 * 图片上传
 * @param file
 * @param type
 * @returns
 */
export const onUpload = (
  file: File,
  type: string
): AxiosPromise<{ url: string }> => {
  const formData = new FormData();
  formData.append("file", file);
  formData.append("type", type);
  return axios.post("/landingPage/upload", formData);
};

/**
 * 模板列表
 * @param type
 * @param category
 * @returns
 */
export const getLandingTempalte = (): any => {
  return axios("/landingPage/bodyTemplates");
};

/**
 * 修改密码
 * @param opasswd
 * @param new_passwd
 * @param new_passwd_repeat
 * @returns
 */
export const changePwdApi = (data: {
  opasswd: string;
  new_passwd: string;
  new_passwd_repeat: string;
}): any => {
  return axios.post("/user/resetPassword", data);
};

/**
 * 模板列表
 * @param campaign_id
 * @param budget_mode
 * @returns
 */
export const changeAdgroupBudget = (data: {
  campaign_id: string;
  budget_mode: string;
  budget: number;
}): any => {
  return axios.post("/ad/updateCampaignBudget", data);
};

/**
 * 财务统计
 * @param campaign_id
 * @param budget_mode
 * @returns
 */
export const getFinanceSum = (
  query: Partial<{
    start_ymd: string;
    end_ymd: string;
    page: number;
    advertiser_id: string;
  }>
): any => {
  return axios("/ad/adFinanceStatSum", { params: query });
};

/**
 * 获取推广链接列表
 * @returns
 */
export const getPromotionList = (data: {
  book_name: string;
  channel_name: string;
  channel_id: string | number;
  page: number;
}) => {
  // return axios("/yuewen/promotions", { params: data });
  return axios(
    `/yuewen/promotions?book_name=${data.book_name}&channel_name=${data.channel_name}&channel_id=${data.channel_id}&page=${data.page}`
  );
};

/**
 *  删除推广信息
 * @param channel_id
 */
export const deletePromotion = (query: { channel_id: number }): any => {
  return axios("/yuewen/deletePromotion", { params: query });
};

//添加推广链接
export const addPromotionLInk = (data: {
  channel_id: string | number;
  channel_name: string;
  book_name: string;
}) => {
  return axios.post("/yuewen/createPromotion", data);
};

//修改回传配置
export const updateReportConfig = (data: {
  channel_id: string | number;
  rate: number;
}) => {
  return axios.post("/yuewen/updateReportConfig", data);
};

/**
 * 获取用户数据
 * @param channel_id
 */
export const getUserData = (query: {
  channel_id: number | string;
  page: number;
  is_paid?: number;
}): any => {
  return axios("/yuewen/registerUsers", { params: query });
};

/**
 *  用户数据强制回传
 * @param uid
 */
export const forceReport = (query: { uid: number | string }): any => {
  return axios("/yuewen/forceReport", { params: query });
};

// 素材库相关接口

/**
 * 获取视频列表
 * @param
 */
export const getVideoList = (query: {
  is_pubic: number | string;
  page: number;
  video_name?: string;
  video_type?: string;
  book_name?: string;
  demander?: string;
  editor?: string;
  uploader?: string;
}): any => {
  return axios("/video/list", { params: query });
};

/**
 * 获取图片列表
 * @param
 */
export const getImageList = (query: {
  is_pubic: number | string;
  page: number;
  image_name?: string;
  image_type?: string;
  book_name?: string;
  demander?: string;
  editor?: string;
  uploader?: string;
}): any => {
  return axios("/image/list", { params: query });
};

/**
 * 删除视频
 * @param
 */
export const deleteVideo = (query: { ids: string }): any => {
  return axios("/video/delete", { params: query });
};

/**
 * 删除图片
 * @param
 */
export const deleteImage = (query: { ids: string }): any => {
  return axios("/image/delete", { params: query });
};

/**
 * 上传视频
 * @data
 */
export const uploadVideo = (data: {
  video: any;
  is_public: number | string;
  duration: number | string;
  width: number | string;
  height: number | string;
}) => {
  // return axios.post("/video/upload", data);
  return axios({
    method: "post",
    url: "/video/upload",
    data,
    headers: {
      "Content-Type": "multipart/form-data",
      contentType: false,
    },
  });
};

/**
 * 上传图片
 * @data
 */
export const uploadImage = (data: {
  image: any;
  is_public: number | string;
}) => {
  // return axios.post("/image/upload", data);
  return axios({
    method: "post",
    url: "/image/upload",
    data,
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
};

/**
 * 获取广告主列表用于推送
 * @param
 */
export const getAdvertiser = (): any => {
  return axios("/ad/advertiser/all");
};

/**
 * 推送素材
 * @param
 */
export const pushMaterial = (query: {
  material_id: string | number;
  advertiser_id: string | number;
}): any => {
  return axios("/material/sync", { params: query });
};

// 员工绩效
/**
 * 获取员工绩效列表
 * @param
 */
export const getStuffPerformance = (query: {
  start_date: string;
  end_date: string;
  uname: string;
  uid?: string | number;
  type: string;
  model: string;
  value: string | number;
  page: number;
  back_amount_order: number | string;
}): any => {
  return axios("/promoter/stat", { params: query });
};

/**
 * 获取员工绩效曲线图数据
 * @param
 */
export const getStuffPerformanceChart = (query: {
  start_date: string;
  end_date: string;
  uname: string;
  uid?: string | number;
  type: string;
  model: string;
  value: string | number;
}): any => {
  return axios("/promoter/statAll", { params: query });
};

/**
 * 获取员工绩效总览
 * @param
 */
export const getStuffPerformanceSum = (query: {
  start_date: string;
  end_date: string;
  uid: any;
}): any => {
  return axios("/promoter/statSum", { params: query });
};

// 建计划模块

/**
 * 获取账户下的广告组
 * @param
 */
export const getAdCampaigns = (query: {
  advertiser_id: string | number;
  campaign_name?: string;
  page: string | number;
  pageSize: 200;
}): any => {
  return axios("/ad/advertiser/campaigns", { params: query });
};
// 创建广告组
/* 创建广告组
 * @param null
 */
export const createAdCampaign = (data: {
  advertiser_id: string | number;
  budget?: string | number;
  campaign_name: string;
  budget_mode: string;
  landing_type: string;
  campaign_type: string;
  marketing_purpose: string;
}) => {
  return axios.post("/ad/campaign/create", data);
};

/**
 * 获取定向包
 * @param
 */
export const getPackage = (query: {
  advertiser_id: string | number;
  page: string | number;
  page_size: string | number;
}): any => {
  return axios("/ad/package/get", { params: query });
};
/**
 * 新建定向包
 * @param
 */
export const createPackage = (data: any): any => {
  return axios.post("/ad/package/create", data);
};

// 获取优化目标
export const getBestTargetApi = (query: {
  advertiser_id: string | number;
  landing_type: string | number;
  marketing_purpose: string | number;
}): any => {
  return axios("/tools/adConvert/optimizedTarget", { params: query });
};

/* 创建计划
 * @param null
 */
export const createPlan = (data: {
  advertiser_id: any;
  campaign_id: any;
  ad_num: string | number;
  is_template: string | number;
  name: string;
  ad_data: object;
}) => {
  return axios.post("/ad/create", data);
};

/**
 * 获取计划列表
 * @param
 */
export const getPlanList = (query: {
  ad_name?: string | number;
  advertiser_name?: string | number;
  campaign_name?: string | number;
  status?: string | number;
  page?: string | number;
}): any => {
  return axios("/ad/create/logs", { params: query });
};
/**
 * 删除摸版
 * @param
 */

export const delModelItem = (query: { id: string }): any => {
  return axios("/ad/create/deleteTemplates", { params: query });
};

/**
 * 删除管理计划
 * @param
 */
export const delPlanList = (query: { log_id: string }): any => {
  return axios("/ad/create/log/delete", { params: query });
};

/**
 * 编辑管理计划
 * @param
 */
export const editPlanLst = (query: any) => {
  return axios("/ad/create/log/edit");
};

/**
 * 获取计划模板
 * @param
 */
export const getPlanTemplate = (query: {
  page?: string | number;
  name?: string;
}): any => {
  return axios("/ad/create/templates", { params: query });
};

/**
 * 获取计划媒体定向包
 * @param
 */
export const getMediaPackage = (query: {
  advertiser_id: any;
  page: string | number;
  page_size: string | number;
}): any => {
  return axios("/ad/flow/package/get", { params: query });
};

/**
 * 创建自定义创意
 * @param
 */
export const createCustomCreative = (data: {
  task_id?: string | number;
  advertiser_id: string | number;
  ad_id: string | number;
  creative_list: any;
  ad_data: any;
}): any => {
  return axios.post("/ad/customCreative/create", data);
};

/**
 *
 * @param
 */
export const getVideoLog = (query: { page?: string | number }): any => {
  return axios.get("/material/uploadStatus", { params: query });
};

/**
 * 回传日志
 * @param campaign_id
 * @param budget_mode
 * @returns
 */
export const backLogList = (
  query: Partial<{
    channel_id: string;
    platform: string;
    page: number;
    report_platform: string;
  }>
): any => {
  return axios("/getReportLogs", { params: query });
};
