export type ArticleCategory = {
  id: number
  name: string
}

export type Article = {
  id: number
  title: string
  subTitle: string
  content: string
  catalogId: number
  createTime: string
  keyword: string
}

export type ArticleItem = {
  TenantId: number
  Title: string
  CatalogId: number
  SubTitle: string
  Thumb: string
  Keyword?: string
  Content: string
  AccessCount: number
  Publish: number
  Tag?: string
  CreateTime: string
  LinkType: number
  LinkId: number
  DeleteTag: number
  Id: number
}

export type ArticleListResult = {
  RowCount: number
  List: ArticleItem[]
}

export const CATEGORIES: ArticleCategory[] = [
  { id: 5, name: "公告中心" },
  { id: 4, name: "直连教程" },
  { id: 3, name: "常见售后" },
  { id: 1, name: "其他帮助" },
  { id: 2, name: "优惠活动" },
  { id: 6, name: "代理合作" },
]

export function transformArticles(items: ArticleItem[]): Article[] {
  return items
    .filter(item => item.Publish === 1 && item.DeleteTag === 0)
    .map(item => ({
      id: item.Id,
      title: item.Title,
      subTitle: item.SubTitle,
      content: item.Content,
      catalogId: item.CatalogId,
      createTime: item.CreateTime.slice(0, 10),
      keyword: item.Keyword ?? "",
    }))
}
