import request from '../config';

export interface ArticleType {
  id: string;
  name: string;
  description?: string;
  visible?: string;
}

export interface Article {
  id: string;
  title: string;
  content?: string;
  image?: string;
  articleType?: string;
  publishTime?: string;
  viewCount?: number;
}

export interface ArticlePageParams {
  pageNum?: number;
  pageSize?: number;
  articleType?: string;
  visible?: string;
  title?: string;
}

export interface ArticlePageResult {
  records: Article[];
  total: number;
  pageNum: number;
  pageSize: number;
}

export const Api = {
  /**
   * 加载文章类型列表
   */
  loadTypeList: async (params?: any) => {
    const visible = params?.visible;
    if (!visible) {
      params = { ...params, visible: '0' };
    }
    return await request.get<ArticleType[]>({ url: `/cms/article-type/portal/list`, params });
  },

  /**
   * 加载文章分页列表
   */
  loadList: async (params?: ArticlePageParams) => {
    return await request.get<ArticlePageResult>({ url: `/cms/article/portal/page-list`, params });
  },

  /**
   * 加载文章详情
   */
  load: async (params: { id: string }) => {
    return await request.get<Article>({ url: `/cms/article/portal/load`, params });
  },

  /**
   * 加载后台文章分页列表（支持权限控制、多条件筛选）
   */
  getArticlePage: async (params?: ArticlePageParams) => {
    return await request.get<ArticlePageResult>({ url: `/cms/article/page`, params });
  }
};
