import { request } from '@/api/request';

/** 资源类型 */
export type ResourceType = 'document' | 'faq';

/** 收藏记录接口 */
export interface Favorite {
  id: number;
  created_at: string;
  resource_type: ResourceType;
  resource_id: number;
  resource_name: string;
  remarks: string;
  is_deleted: boolean;
  resource_data?: any;
}

/** 收藏列表响应 */
export interface FavoriteListResponse {
  total: number;
  page: number;
  page_size: number;
  data: Favorite[];
}

/** 获取收藏列表参数 */
export interface FetchFavoriteListParams {
  page?: number;
  page_size?: number;
  resource_type?: ResourceType;
}

/** 收藏请求参数 */
export interface CollectParams {
  resource_type: ResourceType;
  resource_id: number;
  remarks?: string;
}

/** 取消收藏参数 */
export interface UncollectParams {
  resource_type: ResourceType;
  resource_id: number;
}

/** API响应包装类型 */
export interface ApiResponse<T = any> {
  code: number;
  message: string;
  data: T;
}

/**
 * 获取收藏列表
 */
export async function fetchFavoriteList(
  params: FetchFavoriteListParams = {}
): Promise<ApiResponse<FavoriteListResponse>> {
  return request.get<ApiResponse<FavoriteListResponse>>('/Kb/v1/favorite/list', {
    params,
  });
}

/**
 * 收藏资源
 */
export async function collectResource(
  data: CollectParams
): Promise<ApiResponse<Favorite>> {
  return request.post<ApiResponse<Favorite>>('/Kb/v1/favorite/collect', data);
}

/**
 * 取消收藏
 */
export async function uncollectResource(
  data: UncollectParams
): Promise<ApiResponse<string>> {
  return request.post<ApiResponse<string>>('/Kb/v1/favorite/uncollect', data);
}

/** 资源类型选项 */
export const resourceTypeOptions = [
  { label: '文档', value: 'document' },
  { label: 'FAQ', value: 'faq' },
];