/**
 * @description 搜索相关API
 * @author yslg
 * @since 2025-10-15
 */

import { api } from '@/apis/index';
import type { Resource, ResultDomain } from '@/types';

/**
 * 搜索API服务
 */
export const searchApi = {
  /**
   * 模糊检索资源
   * @param keyword 关键词
   * @returns Promise<ResultDomain<Resource>>
   */
  async searchResources(keyword: string): Promise<ResultDomain<Resource>> {
    const response = await api.get<Resource>('/homepage/search', { keyword });
    return response.data;
  },

  /**
   * 实时搜索建议
   * @param keyword 关键词
   * @returns Promise<ResultDomain<any>>
   */
  async getSearchSuggestions(keyword: string): Promise<ResultDomain<any>> {
    const response = await api.get<any>('/homepage/search/suggestions', { keyword });
    return response.data;
  },

  /**
   * 获取热门搜索词
   * @returns Promise<ResultDomain<any>>
   */
  async getHotKeywords(): Promise<ResultDomain<any>> {
    const response = await api.get<any>('/homepage/search/hot-keywords');
    return response.data;
  },

  /**
   * 搜索新闻
   * @param keyword 关键词
   * @returns Promise<ResultDomain<Resource>>
   */
  async searchNews(keyword: string): Promise<ResultDomain<Resource>> {
    const response = await api.get<Resource>('/homepage/search/news', { keyword });
    return response.data;
  },

  /**
   * 搜索课程
   * @param keyword 关键词
   * @returns Promise<ResultDomain<any>>
   */
  async searchCourses(keyword: string): Promise<ResultDomain<any>> {
    const response = await api.get<any>('/homepage/search/courses', { keyword });
    return response.data;
  }
};
