import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { ArticleVO, ArticleForm, ArticleQuery } from '@/api/system/article/types';

/**
 * 查询文章(可用于活动预热)列表
 * @param query
 * @returns {*}
 */

export const listArticle = (query?: ArticleQuery): AxiosPromise<ArticleVO[]> => {
  return request({
    url: '/system/article/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询文章(可用于活动预热)详细
 * @param id
 */
export const getArticle = (id: string | number): AxiosPromise<ArticleVO> => {
  return request({
    url: '/system/article/' + id,
    method: 'get'
  });
};

/**
 * 新增文章(可用于活动预热)
 * @param data
 */
export const addArticle = (data: ArticleForm) => {
  return request({
    url: '/system/article',
    method: 'post',
    data: data
  });
};

/**
 * 修改文章(可用于活动预热)
 * @param data
 */
export const updateArticle = (data: ArticleForm) => {
  return request({
    url: '/system/article',
    method: 'put',
    data: data
  });
};

/**
 * 删除文章(可用于活动预热)
 * @param id
 */
export const delArticle = (id: string | number | Array<string | number>) => {
  return request({
    url: '/system/article/' + id,
    method: 'delete'
  });
};

/**
 * 修改文章默认状态
 * @param data - 文章BO对象
 */
export const changeArticleDefault = (data: ArticleForm): AxiosPromise<void> => {
  return request({
    url: '/system/article/changeArticleDefault',
    method: 'post',
    data: data
  });
};

/**
 * 查询赛事项目数量
 * @returns {*}
 */
export const getArticleCount = () => {
  return request({
    url: '/system/article/count',
    method: 'get'
  });
};
