import { request } from '@/api/request'
import type { KbReply } from './types'

export type TrashResourceType = 'document' | 'faq'

/** 回收站记录。 */
export interface TrashRecord {
  id: number
  created_at: string
  updated_at: string
  resource_type: TrashResourceType
  resource_id: number
  resource_name: string
  deleted_by: number
  deleted_name: string
  deleted_time: string
  delete_reason: string
  original_data: string
  remarks: string
}

export interface TrashPage {
  total: number
  page: number
  page_size: number
  data: TrashRecord[]
}

export interface FetchTrashListParams {
  page?: number
  page_size?: number
  resource_type?: TrashResourceType
}

export const resourceTypeOptions: Array<{ label: string; value: TrashResourceType }> = [
  { label: '文档', value: 'document' },
  { label: 'FAQ', value: 'faq' },
]

/** 获取回收站资源类型文案。 */
export const getResourceTypeText = (type: string) => ({ document: '文档', faq: 'FAQ' })[type] || type

/** 获取回收站资源类型颜色。 */
export const getResourceTypeColor = (type: string) => ({ document: 'blue', faq: 'green' })[type] || 'gray'

/** 获取回收站列表。 */
export const fetchTrashList = (params: FetchTrashListParams) => request.get<KbReply<TrashPage>>('/Kb/v1/trash/list', { params })

/** 恢复资源。 */
export const restoreTrash = (id: number) => request.post<KbReply<string>>('/Kb/v1/trash/restore', { id })

/** 彻底删除资源。 */
export const deleteTrash = (id: number) => request.post<KbReply<string>>('/Kb/v1/trash/delete', { id })
