import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { DictVO, DictForm, DictQuery } from '@/api/system/dict/types';

/**
 * 查询字典组列表
 * @param query
 * @returns {*}
 */

export const listDict = (query?: DictQuery): AxiosPromise<{records:DictVO[]}> => {
  return request({
    url: '/sys/dict/pageDict',
    method: 'post',
    data: query
  });
};
/**
 * 查询字典组列表
 * @param query
 * @returns {*}
 */

export const listDetialByCodes = (codes?: String[]): AxiosPromise<any> => {
  return request({
    url: '/sys/dict/listDetialByCodes',
    method: 'post',
    data: {codels: codes}
  });
};

/**
 * 查询字典组详细
 * @param dictId
 */
export const getDict = (dictId: string | number): AxiosPromise<DictVO> => {
  return request({
    url: '/system/dict/' + dictId,
    method: 'get'
  });
};

/**
 * 新增字典组
 * @param data
 */
export const addDict = (data: DictForm) => {
  return request({
    url: '/sys/dict/saveDict',
    method: 'post',
    data: data
  });
};


/**
 * 修改字典组
 * @param data
 */
export const updateDict = (data: DictForm) => {
  return request({
    url: '/system/dict',
    method: 'put',
    data: data
  });
};

/**
 * 删除字典组
 * @param dictId
 */
export const delDict = (dictId: string | number ) => {
  return request({
    url: '/sys/dict/deleteDict',
    method: 'post',
      data: {ids: [dictId]}
  });
};
