/**
 * @description 新闻相关API
 * @author yslg
 * @since 2025-10-15
 */

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

/**
 * 新闻API服务
 */
export const newsApi = {
  /**
   * 获取思政新闻概览
   * @param pageNum 页码
   * @param pageSize 每页条数
   * @returns Promise<ResultDomain<Resource>>
   */
  async getNewsOverview(pageNum?: number, pageSize?: number): Promise<ResultDomain<Resource>> {
    const response = await api.get<Resource>('/homepage/news/overview', {
      pageNum,
      pageSize
    });
    return response.data;
  },

  /**
   * 点击跳转二级详情页
   * @param newsID 新闻ID
   * @returns Promise<ResultDomain<Resource>>
   */
  async getNewsDetail(newsID: string): Promise<ResultDomain<Resource>> {
    const response = await api.get<Resource>(`/homepage/news/detail/${newsID}`);
    return response.data;
  },

  /**
   * 获取最新思政新闻
   * @param limit 限制数量
   * @returns Promise<ResultDomain<Resource>>
   */
  async getLatestNews(limit?: number): Promise<ResultDomain<Resource>> {
    const response = await api.get<Resource>('/homepage/news/latest', { limit });
    return response.data;
  }
};
