import service from '@/utils/request/index'
import type {
  AddOrUpdateArticleDto,
  ArticleItemDto,
  ArticleSearchParams,
  InterviewOptionDto,
  ColumnOptionDto,
  AddCommentDto,
  CommentItemDto,
  CommentSearchParams,
  InterviewItemDto,
  AtUserInfoDto,
  ColumnItemDto,
  VideoOptionDto,
  CommentChildrenSearchParams,
  SearchMoreColumnParams,
  SearchMoreColumnItemDto,
  SearchMoreVideoParams,
  SearchMoreVideoItemDto,
  SecondCommentItemDto,
  UpdateArticleRecommendAndSortDto,
  RelatedColumnItemDto,
  RelatedColumnParams,
  UpdateArticleShowLatestDto,
} from './types'
import type { BackendServicePageResult, PageSearchParams } from '@/utils/request/types'
import { SpecificVideoRewardEnum, BooleanFlag } from '@/constants'

// 文章相关的接口(帖子 视频 实践等)

/**
 * 发布文章 暂时由 有帖子 专栏 专访
 */
export const addOrUpdateArticle = (data: AddOrUpdateArticleDto) => {
  return service.request<boolean>({
    url: '/api/cultureArticle/addOrUpdateArticle',
    method: 'POST',
    data,
  })
}

/**
 * 文章列表
 */
export const getArticleList = (data: ArticleSearchParams) => {
  return service.request<BackendServicePageResult<ArticleItemDto>>({
    url: '/api/cultureArticle/listByPage',
    method: 'POST',
    data,
  })
}

/**
 * 文章详情
 */
export const getArticleDetail = (articleId: number | string) => {
  return service.request<ArticleItemDto>({
    url: `/api/cultureArticle/getArticleDetail?articleId=${articleId}`,
    method: 'POST',
  })
}

/**
 * 获取专访列表选项 --不分页 用户新增时候选择
 */
export const getInterviewOptions = () => {
  return service.request<InterviewOptionDto[]>({
    url: '/api/cultureColumn/listNoPage?type=interview',
    method: 'POST',
  })
}

/**
 * 获取首页专访列表list —— 分页
 */
export const getInterviewList = (data: PageSearchParams) => {
  return service.request<BackendServicePageResult<InterviewItemDto>>({
    url: '/api/yaCulture/listByPage',
    method: 'POST',
    data: {
      ...data,
      type: 'interview',
    },
  })
}

/**
 * 获取专栏列表选项-- 不分页 用户新增时候选择
 */
export const getColumnOptions = () => {
  return service.request<ColumnOptionDto[]>({
    url: '/api/cultureColumn/listNoPage?type=column',
    method: 'POST',
  })
}

/**
 * 获取视频栏目列表 --不分页 用户新增的时候传
 */
export const getVideoOptions = () => {
  return service.request<VideoOptionDto[]>({
    url: '/api/cultureColumn/listNoPage?type=video',
    method: 'POST',
  })
}

/**
 * 获取首页专栏列表list —— 分页
 */
export const getColumnList = (data: PageSearchParams) => {
  return service.request<BackendServicePageResult<ColumnItemDto>>({
    url: '/api/yaCulture/listByPage',
    method: 'POST',
    data: {
      ...data,
      type: 'column',
    },
  })
}

/**
 * 获取专栏列表查看更多
 */
export const getColumnListViewMore = (data: SearchMoreColumnParams) => {
  return service.request<BackendServicePageResult<SearchMoreColumnItemDto>>({
    url: '/api/yaCulture/viewMore',
    method: 'POST',
    data: {
      type: 'column',
      ...data,
    },
  })
}
/**
 * 获取首页视频列表list —— 分页
 */
export const getVideoList = (data: PageSearchParams) => {
  return service.request<BackendServicePageResult<ColumnItemDto>>({
    url: '/api/yaCulture/listByPage',
    method: 'POST',
    data: {
      ...data,
      type: 'video',
    },
  })
}

/**
 * 获取视频列表查看更多
 */
export const getVideoListViewMore = (data: SearchMoreVideoParams) => {
  return service.request<BackendServicePageResult<SearchMoreVideoItemDto>>({
    url: '/api/yaCulture/viewMore',
    method: 'POST',
    data: {
      type: 'video',
      ...data,
    },
  })
}
/**
 * 点赞或者取消点赞文章
 */
export const addOrCanceArticlelLike = (articleId: number | string) => {
  return service.request<boolean>({
    url: `/api/cultureArticle/likeArticle?articleId=${articleId}`,
    method: 'POST',
  })
}

/**
 * 收藏或者取消收藏文章
 */
export const addOrCanceArticlelCollect = (articleId: number | string) => {
  return service.request<boolean>({
    url: `/api/cultureArticle/collectArticle?articleId=${articleId}`,
    method: 'POST',
  })
}

/**
 * 获取评论列表
 */
export const getCommentList = (data: CommentSearchParams) => {
  return service.request<BackendServicePageResult<CommentItemDto>>({
    url: `/api/cultureComment/getComment`,
    method: 'POST',
    data,
  })
}

/**
 * 新增评论
 */
export const addComment = (data: AddCommentDto) => {
  return service.request<boolean>({
    url: `/api/cultureComment/addComment`,
    method: 'POST',
    data,
  })
}

/**
 * 点赞评论
 */
export const addOrCancelCommentLike = (commentId: number | string) => {
  return service.request<boolean>({
    url: `/api/cultureComment/likeComment?commentId=${commentId}`,
    method: 'POST',
  })
}

/**
 * 修改文章的是否推荐/置顶字段
 */
export const updateArticleRecommendAndSort = (data: UpdateArticleRecommendAndSortDto) => {
  return service.request({
    url: `/api/cultureArticle/isRecommend`,
    method: 'POST',
    data,
  })
}

/**
 * 删除文章接口
 */
export const deleteArticle = (id: number) => {
  return service.request({
    url: `/api/personalCenter/deleteArticle`,
    method: 'POST',
    data: {
      id,
    },
  })
}

/**
 * 删除评论接口
 */
export const deleteComment = (commentId: number) => {
  return service.request({
    url: `/api/cultureComment/deleteComment?commentId=${commentId}`,
    method: 'POST',
  })
}

/**
 * 给文章投币
 */

export const addOrCancelArticleReward = (data: { articleId: number; ayabi: number }) => {
  return service.request({
    url: `/api/culture/action/record/reward`,
    method: 'POST',
    data,
  })
}

/**
 * 给视频播放量加1
 */
export const addVideoPlayCount = (articleId: number) => {
  return service.request({
    url: `/api/cultureArticle/addVideoPlayCount?articleId=${articleId}`,
    method: 'POST',
  })
}

/**
 * 展开评论 获取子评论 分页
 */
export const getCommentChildren = (data: CommentChildrenSearchParams) => {
  return service.request<BackendServicePageResult<CommentItemDto>>({
    url: `/api/cultureComment/comment/children`,
    method: 'POST',
    data,
  })
}

/**
 * 个人中心——问吧回答问题列表
 */
export const answerQuestionPage = (data: PageSearchParams) => {
  return service.request<BackendServicePageResult<ArticleItemDto>>({
    url: `/api/personalCenter/addQuestionPage`,
    method: 'POST',
    data,
  })
}

/**
 * 问吧列表 添加问题到回答问题列表
 */
export const addOrCancelToAnswerList = (data: { articleId: number }) => {
  return service.request<boolean>({
    url: `/api/cultureQuestionAdd/addOrCancel`,
    method: 'POST',
    data,
  })
}

/**
 * 问吧 用户添加问题的数量
 */
export const getUserQestionNum = () => {
  return service.request<number>({
    url: `/api/cultureQuestionAdd/addQuestionNum`,
    method: 'POST',
  })
}

/**
 * 举报帖子
 */
export const addComplaint = (data: { articleId: number; reason: string }) => {
  return service.request<boolean>({
    url: `/cultureReport/addReport`,
    method: 'POST',
    data,
  })
}

/**
 * 问吧-获取回答列表的评论(二级评论)
 */
export const getSecondCommentList = (data: CommentSearchParams) => {
  return service.request<BackendServicePageResult<SecondCommentItemDto>>({
    url: `/api/cultureComment/getQuestionComment`,
    method: 'POST',
    data,
  })
}

/**
 * 问吧 获取二级评论的子评论
 */

export const getSecondCommentChildren = (data: {
  pid: number
  current: number
  size: number
  articleId: number
}) => {
  return service.request<BackendServicePageResult<CommentItemDto>>({
    url: `/api/cultureComment/getAllComment`,
    method: 'POST',
    data,
  })
}

/**
 * 根据commentid 获取这个评论的详情
 */
export const getCommentDetail = (id: number) => {
  return service.request<CommentItemDto>({
    url: `/api/cultureComment/questionCommentData`,
    method: 'POST',
    data: {
      id,
    },
  })
}

/**
 * 获取特定视频观看奖励
 */
export const getSpecificVideoWatchReward = (pageKey: SpecificVideoRewardEnum) => {
  return service.request<boolean>({
    url: `/api/yaCulture/bossVideo/view`,
    method: 'POST',
    data: {
      pageKey,
    },
  })
}

/**
 * 置顶 取消置顶评论
 */
export const topOrCancelTopComment = (commentId: number) => {
  return service.request<boolean>({
    url: `/api/cultureComment/topComment?commentId=${commentId}`,
    method: 'POST',
  })
}

/**
 *  获取可@的用户列表
 */
export const getAtUserList = (
  data: PageSearchParams & {
    findType?: BooleanFlag
    findValue?: string
  },
) => {
  return service.request<BackendServicePageResult<AtUserInfoDto>>({
    url: `/api/auth/getUserInfo`,
    method: 'POST',
    data,
  })
}

/**
 * 根据标签获取专栏相关推荐
 */
export const getRelatedColumnList = (data: RelatedColumnParams) => {
  return service.request<RelatedColumnItemDto[]>({
    url: '/api/cultureArticle/relatedByTag',
    method: 'POST',
    data,
  })
}

/**
 * 修改视频是否在首页最新列表展示
 */
export const updateArticleShowLatest = (data: UpdateArticleShowLatestDto) => {
  return service.request<boolean>({
    url: '/api/cultureArticle/updateShowLatest',
    method: 'POST',
    data,
  })
}
