import NewAxiosInstanceFunc from '../Service/NewAxiosInstance'
import { INewResponse } from '../Service/INewResponse'
import { IItemType } from './components/Item.component'
import { IIndepthArticleItem } from 'Indepth/Indepth.service'
export const visitorToken =
  'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMzA1MjI2OTYyMyIsInBob25lX251bWJlciI6IjEzMDUyMjY5NjIzIiwibmFtZSI6IuW8oOaAneiOuSIsImVudHJhbmNlIjoiZmljYyIsImlhdCI6MTY2MjcwNjU4MiwiZXhwIjoxNjYyNzEwMTgyfQ.yLV17GRkUc8lHh1gHhLrKU4AIfW6zbL0P2Qb8lpIumU'
export interface IGetHomeListParams {
  PageSize: number // 每页数据条数
  CurrentIndex: number // 当前页页码，从1开始
  ChartPermissionId?: number // 品类id，最新传0(纪要时必填)
  CtagId?: number // 图表子类ID(图表时必填)
  ListType: number // 列表类型，1最新，2 纪要 ，3图表 默认1
}
export interface IGetHomeListRes {
  ChartList: IHomeChartListItem[]
  List: IIndepthArticleItem[]
  Paging: IPaging
}
export interface IGetSearchArticleListRes {
  ChartList: IHomeChartListItem[]
  List: IGetListBySearchItem[]
  Paging: IPaging
}
export interface IPaging {
  CurrentIndex: number
  IsEnd: boolean
  IsStart: boolean
  NextIndex: number
  PageSize: number
  Pages: number
  PreviousIndex: number
  Totals: number
}
export interface IHomeChartListItem {
  BodyHtml: string
  ChartId: number
  CreateDate: string
  CtagName: string // 子类名称
  CtagNamePc: string // Pc端所有的分类名称
  CtagNameTwo: string // 子类名称
  HttpUrl: string
  IsNeedJump: boolean // 是否需要跳转链接地址
  IsTop: boolean // 是否置顶
  NumTop: number // 置顶数量
  PtagName: string // 父类名称
  PtagNameTwo: string // 父类名称
  Source: number // 来源 1:文章, 2:图表
  Title: string // 标题
  TitleEn: string // 英文标题
  _itemType?: IItemType
  LabelList: {
    PtagName: string
    CtagName: string
  }[]
}
export interface IHomeArticleListItem extends IGetListBySearchItem {
  Abstract: string // 摘要
  Annotation: string // 核心观点
  BodyHtml: string // 内容带有HTML标签
  CategoryName: string // 一级分类
  CreateDate: string // 创建时间
  HttpUrl: string // 文章链接跳转地址
  IsNeedJump: boolean // 是否需要跳转链接地址
  IsResearch: boolean // 是否属于研选
  Pv: number
  SubCategoryName: string // 二级分类
  TitleEn: string // 英文标题
  UpdateFrequency: string // 更新周期
  _itemType?: IItemType
  IsRed: boolean
}
export interface IPermissionListItem {
  ChartPermissionId: number
  PermissionName: string
}
export interface ISearchKeyWordRes {
  ListHistory: { KeyWord: string }[] // 关键词搜索记录
  ListHot: { KeyWord: string }[] // 热搜关键词
  ListRecommend: { KeyWord: string }[] // 搜索推荐
}
export interface IGetListBySearchParams {
  PageSize: number
  CurrentIndex: number
  KeyWord: string // 搜索关键词
  OrderColumn?: string // 排序字段 ，Comprehensive综合 ，Matching匹配度 ，PublishDate 发布时间
  ListType: number // 列表类型，1最新/全部，2 纪要 ，3图表 默认1
}
export interface IGetListBySearchItem {
  ArticleId: number
  Body: string[] // 搜索结果
  CategoryId: string // 文章分类
  ExpertBackground: string // 专家背景
  ImgUrlPc: string // 图片链接
  PublishDate: string
  Source: number // 来源 1:文章, 2:图表
  Title: string
  IsResearch: boolean // 是否属于研选
  Pv: number
}
export interface IArcticleDetail {
  Abstract: string // 摘要
  Annotation: string // 核心观点
  ArticleId: number
  ArticleIdMd5: string // 报告MD5id
  ArticleTypeId: number
  Body: string // 内容
  CategoryId: number // 分类ID
  CategoryName: string // 一级分类
  CollectionNum: number // 收藏数量
  CreateDate: string
  DepartmentDetail: {
    CreateTime: string
    DepartmentId: number
    ImgUrl: string
    IsFollow: boolean // 是否关注
    NickName: string
  }
  DepartmentId: number // 作者Id
  DepartmentImgUrl: string // 作者头像
  Disclaimers: string // 免责声明
  FollowNum: number // 关注数量
  HttpUrl: string // 文章链接跳转地址
  InterviewApplyStatus: string // 当前访谈申请状态：'待邀请','待访谈','已完成','已取消'
  IsApplyAppointmentExpert: boolean // 是否预约过专家
  IsCollect: boolean // 是否收藏:true，已收藏，false:未收藏
  IsFollow: boolean // 是否关注
  IsInterviewApply: boolean // 是否申请访谈:true，已申请，false:未申请
  IsNeedJump: boolean // 是否需要跳转链接地址 true 是策略平台的报告， false 是研选
  IsReport: number // 是否属于报告，1是，0否
  IsSpecialArticle?: boolean // 是否是专项调研
  NickName: string
  PublishDate: string
  Seller: {
    SellerMobile: string
    SellerName: string
  }
  ShareImg: string // 分享图片
  SubCategoryName: string // 二级分类
  Title: string
  // HasPermission 1:有该行业权限,正常展示，2：无该行业权限，不存在权益客户下，3:无该品类权限,已提交过申请，4：无该行业权限,未提交过申请，5：潜在客户，未提交过申请，6：潜在客户,已提交过申请
}
export interface IArcticleHotListItem {
  ArticleId: number
  CollectNum: number // 收藏人数
  DepartmentId: number // 作者Id
  IndustrialManagementId: number // 产业Id
  IndustryName: string // 产业名称
  IsCollect: boolean // 本人是否收藏
  MyCollectNum: number // 文章收藏数量
  NickName: string // 作者昵称
  PublishDate: string
  Pv: number
  Source: number // 来源 1:弘则资源包（报告）、2：研选主题（报告）
  Title: string
}
export interface IArcticleInfo {
  Detail: IArcticleDetail
  HasPermission: number
  IsCompanyApply: boolean // 机构是否申请过试用
  IsNeedBusinessCard: boolean // 是否需要上传名片
  IsResearch: boolean // 是否是买方研选
  IsShowWxPay: boolean // 是否展示微信支付
  IsSpecialArticle: boolean // 是否是专项调研
  Mobile: string
  PopupMsg: string
  PopupPriceMsg: string // 价格弹窗信息
  SellerMobile: string
  SellerName: string
  GoodsList: IGoodsListItem[] // 商品信息
}
export interface IGoodsListItem {
  CurrentPrice: string //商品现价（当时出售的价格）
  GoodsId: number //商品ID
  GoodsName: string //商品名称
  PopupPriceMsg: string //价格弹窗信息
  Price: string //商品原价格
}
export interface IApplyTryParams {
  ApplyMethod: number // 1:已付费客户申请试用，2:非客户申请试用,3:非客户申请试用(ficc下，不需要进行数据校验
  BusinessCardUrl?: string // 名片地址
  CompanyName?: string // 公司名称
  DetailId?: number // 详情ID
  RealName?: string // 姓名
  TryType?: string // 提交类型，Article：文章、Activity：活动
}
export interface IIntroduceItem {
  Img: string
  Height: string
}
export interface IBusinessCardParams {
  BusinessCardUrl: string //名片地址
  RealName: string //用户实际名称
  Mobile: string //手机号
  CompanyName: string //公司名称
  InviteShareCode: string //邀请人code
}
export interface IOrderInfoRes {
  CodeUrl: string //二维码参数链接
  OrderCode: string //订单编号rl
  PayTimeCountdown: number //订单倒计时
}
export interface IOrderPayStatusRes {
  IsSignUp: boolean //是否自动报名
  IsPublicActivitie: boolean //是否是公开活动
  OrderCode: string //订单编号
  OrderType: number //订单类型 1：畅读卡订单，2：单场付费订单
  EndDate: string //结束日期
  OrderStatus: EOrderStatus //订单状态,0:已取消、1:待支付、2:已支付、3:已退款
  SourceId: number //文章ID
  Source: string //来源\n报告 ：article\n活动 ：activity
}
export enum EOrderStatus {
  Cancel = 0, // 0:已取消
  WaitPay = 1, // 1:待支付
  Payed = 2, // 2:已支付
  Refund = 3 // 3:已退款
}

export const MaterialService = {
  getHomeList: (params: IGetHomeListParams): INewResponse<IGetHomeListRes> =>
    NewAxiosInstanceFunc({
      url: `/home/list`,
      method: 'get',
      params: { ...params }
    }),
  getPermissionList: (): INewResponse<{ List: IPermissionListItem[] }> =>
    NewAxiosInstanceFunc({
      url: `/permission/list`,
      method: 'get'
    }),
  getSearchKeyWordList: (): INewResponse<ISearchKeyWordRes> =>
    NewAxiosInstanceFunc({
      url: `/search/keyWord`,
      method: 'get'
    }),
  getListBySearch: (params: IGetListBySearchParams): INewResponse<IGetSearchArticleListRes> =>
    NewAxiosInstanceFunc({
      url: `/search/list`,
      method: 'get',
      params: { ...params }
    }),
  getArcticleDetail: (ArticleId: number, InviteShareCode?: string): INewResponse<IArcticleInfo> =>
    NewAxiosInstanceFunc({
      url: `/article/detail`,
      method: 'get',
      params: { ArticleId, InviteShareCode }
    }),
  getArcticleHotList: (ArticleId: number): INewResponse<{ List: IArcticleHotListItem[] }> =>
    NewAxiosInstanceFunc({
      url: `/article/hotList`,
      method: 'get',
      params: { ArticleId }
    }),
  getResearchIntroduce: (): INewResponse<{ List: IIntroduceItem[] }> =>
    NewAxiosInstanceFunc({
      url: `/config/research/introduce`,
      method: 'get'
    }),
  getResearchQuotation: (): INewResponse<{ List: IIntroduceItem[] }> =>
    NewAxiosInstanceFunc({
      url: `/config/research/quotation`,
      method: 'get'
    }),
  getOrderPayStatus: (OrderCode: string): INewResponse<IOrderPayStatusRes> =>
    NewAxiosInstanceFunc({
      url: `/order/orderPay/detail`,
      method: 'get',
      params: { OrderCode }
    }),
  postActicleInterview: (ArticleId: number): INewResponse =>
    NewAxiosInstanceFunc({
      url: `/article/interview/apply`,
      method: 'post',
      data: { ArticleId }
    }),
  postActicleCollect: (ArticleId: number): INewResponse =>
    NewAxiosInstanceFunc({
      url: `/article/collect`,
      method: 'post',
      data: { ArticleId }
    }),
  postActicleAskAdd: (ArticleId: number, Content: string): INewResponse =>
    NewAxiosInstanceFunc({
      url: `/article/askAdd`,
      method: 'post',
      data: { ArticleId, Content }
    }),
  postApplyTry: (params: IApplyTryParams): INewResponse =>
    NewAxiosInstanceFunc({
      url: `/user/apply/try`,
      method: 'post',
      data: { ...params }
    }),
  postUploadImage: (file: any): INewResponse => {
    const formData = new FormData()
    formData.set('file', file)
    return NewAxiosInstanceFunc({
      url: `/resource/image/upload`,
      method: 'post',
      data: formData
    })
  },
  postReportComment: (ArticleId: number, Content: string): INewResponse =>
    NewAxiosInstanceFunc({
      url: `/report/commentAdd`,
      method: 'post',
      data: { ArticleId, Content } // SourceType-视频来源: 1-音频; 2-活动视频; 3-微路演视频
    }),
  postAddReadTime: (ArticleId: number, StopTime: number, OutType?: number): INewResponse =>
    NewAxiosInstanceFunc({
      url: `/article/addStopTime`,
      method: 'post',
      data: { ArticleId, StopTime, OutType } // 退出方式，1正常退出，2强制关闭
    }),
  postReadingTime: (ArticleId: number, StopTime: number, Source: number, OutType?: number): INewResponse =>
    NewAxiosInstanceFunc({
      url: `/report_selection/addStopTime`,
      method: 'post',
      data: { ArticleId, StopTime, Source, OutType } // Source-来源，1:深度研究、2:本周研究汇总、3:上周纪要汇总 OutType-退出方式，1正常退出，2强制关闭
    }),
  postAskAppointmentExpert: (ArticleId: number): INewResponse =>
    NewAxiosInstanceFunc({
      url: `/article/applyAppointmentExpert`,
      method: 'post',
      data: { ArticleId }
    }),
  postColumnClickRecord: (SpecialId: number, StopTime: number): INewResponse =>
    NewAxiosInstanceFunc({
      url: `/yanxuan_special/record`,
      method: 'post',
      data: { SpecialId, StopTime }
    }),
  postUploadBusinessCard: (params: IBusinessCardParams): INewResponse =>
    NewAxiosInstanceFunc({
      url: `/user/upload/UserBusinessCard`,
      method: 'post',
      data: { ...params }
    }),
  postCreateOrderByArticle: (
    GoodsId: number,
    SourceId: number,
    InviteShareCode: string | null
  ): INewResponse<IOrderInfoRes> =>
    NewAxiosInstanceFunc({
      url: `/order/addByArticle`,
      method: 'post',
      data: { GoodsId, SourceId, InviteShareCode }
    }),
  postCreateOrderByActivity: (
    GoodsId: number,
    SourceId: number,
    InviteShareCode: string | null
  ): INewResponse<IOrderInfoRes> =>
    NewAxiosInstanceFunc({
      url: `/order/addByActivity`,
      method: 'post',
      data: { GoodsId, SourceId, InviteShareCode }
    }),
  postCreateOrderByYanXuan: (
    GoodsId: number,
    SourceId: number,
    InviteShareCode: string | null
  ): INewResponse<IOrderInfoRes> =>
    NewAxiosInstanceFunc({
      url: `/order/addByYanxuanspecial`,
      method: 'post',
      data: { GoodsId, SourceId, InviteShareCode }
    })
}
