import { request } from '@/utils/http'
import type { ResultData } from '@/utils/http'

export type ArticleDetailType = {
  id: number
  title: string
  content: string
  createTime: string
  readCount: number
  categoryId: number
  articleId: number
  children?: ArticleDetailType[]
}


export type ArticleDetailMenuType = {
  level: number
  text: string
  children: ArticleDetailMenuType[]
}

export const getArticleDetail = (id: number): Promise<ResultData<ArticleDetailType>> =>
  request.get(`web/article/${id}`)

export const getArticleCount = (id: number): Promise<ResultData<boolean>> =>
  request.get(`web/article/count/${id}`)

export const getArticleSearch = (keyword: string): Promise<ResultData<ArticleDetailType[]>> =>
  request.get(`web/search`, { key: keyword })

export const getArticlesByCateId = (cid: number): Promise<ResultData<ArticleDetailType[]>> =>
  request.get(`web/articleWithCate/${cid}`)

export const getNearArticles = (cid: number): Promise<ResultData<ArticleDetailType[]>> =>
  request.get(`web/article/near/${cid}`)
