import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { WordsVO, WordsForm, WordsQuery } from '@/api/system/physical/words/types';

/**
 * 查询敏感词管理：用于内容安全过滤，支持分类与启停控制列表
 * @param query
 * @returns {*}
 */

export const listWords = (query?: WordsQuery): AxiosPromise<WordsVO[]> => {
  return request({
    url: '/physical/words/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询敏感词管理：用于内容安全过滤，支持分类与启停控制详细
 * @param id
 */
export const getWords = (id: string | number): AxiosPromise<WordsVO> => {
  return request({
    url: '/physical/words/' + id,
    method: 'get'
  });
};

/**
 * 新增敏感词管理：用于内容安全过滤，支持分类与启停控制
 * @param data
 */
export const addWords = (data: WordsForm) => {
  return request({
    url: '/physical/words',
    method: 'post',
    data: data
  });
};

/**
 * 修改敏感词管理：用于内容安全过滤，支持分类与启停控制
 * @param data
 */
export const updateWords = (data: WordsForm) => {
  return request({
    url: '/physical/words',
    method: 'put',
    data: data
  });
};

/**
 * 删除敏感词管理：用于内容安全过滤，支持分类与启停控制
 * @param id
 */
export const delWords = (id: string | number | Array<string | number>) => {
  return request({
    url: '/physical/words/' + id,
    method: 'delete'
  });
};
export const downloadImportWordsTemplates = async () => {
  const res = await request({
    url: '/physical/words/importWordsTemplate',
    method: 'POST',
    responseType: 'blob'
  });
  return res;
};
export const importWords = (data: FormData) => {
  return request({
    url: '/physical/words/importWords',
    method: 'post',
    data: data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
};
