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

/**
 * 查询文章列表
 * @param query
 * @returns {*}
 */

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

/**
 * 查询文章详细
 * @param id
 */
export const getArticle = (id: string | number): AxiosPromise<ArticleVO> => {
  return request({
    url: '/smarttrace/article/getInfo/' + id,
    method: 'get'
  });
};

/**
 * 新增文章
 * @param data
 */
export const addArticle = (data: ArticleForm) => {
  return request({
    url: '/smarttrace/article/add',
    method: 'post',
    data: data
  });
};

/**
 * 修改文章
 * @param data
 */
export const updateArticle = (data: ArticleForm) => {
  return request({
    url: '/smarttrace/article/edit',
    method: 'post',
    data: data
  });
};

/**
 * 删除文章
 * @param id
 */
export const delArticle = (id: string | number | Array<string | number>) => {
  return request({
    url: '/smarttrace/article/remove/' + id,
    method: 'get'
  });
};
