/*
 * @Author: wfl
 * @LastEditors: mhj
 * @description:
 * @updateInfo:
 * @Date: 2022-08-11 10:14:30
 * @LastEditTime: 2022-08-24 14:39:47
 */
import { defHttp } from '@/mainApp/utils/http/axios';
import { ApiModel } from '../model/baseModel';

enum Api {
  GetDictByID = '/server/dict/item/map',
  GetDictPage = '/server/dict/page',
  //ͨ���ֵ��Ż�ȡ�ֵ����б�
  GetDictItemList = '/server/dict/item/list',
  //�����ֵ���༭��ɾ��
  DictItem = '/server/dict/item',
  //�����ֵ�
  AddDict = '/server/dict',
}

const dictApi = {
  getDictById: (dictId): Promise<ApiModel> => {
    return defHttp.get({ url: Api.GetDictByID, params: { dictId } });
  },
  getDictPage: (params): Promise<ApiModel> => {
    return defHttp.post({ url: Api.GetDictPage, params });
  },
  getDictItem: (dictId): Promise<ApiModel> => {
    return defHttp.get({ url: Api.GetDictItemList, params: { dictId } });
  },
  //�����ֵ���
  addDictItem: (params): Promise<ApiModel> => {
    return defHttp.post({ url: Api.DictItem, params });
  },
  //�༭�ֵ���
  editDictItem: (params): Promise<ApiModel> => {
    return defHttp.put({ url: Api.DictItem, params });
  },
  //ɾ���ֵ���
  delDictItem: (id): Promise<ApiModel> => {
    return defHttp.delete({
      url: `${Api.DictItem}?dictItemId=${id}`,
    });
  },

  //�����ֵ�
  addDict: (params): Promise<ApiModel> => {
    return defHttp.post({ url: Api.AddDict, params });
  },
  //�༭�ֵ���
  editDict: (params): Promise<ApiModel> => {
    return defHttp.put({ url: Api.AddDict, params });
  },
  //ɾ���ֵ���
  delDict: (id): Promise<ApiModel> => {
    return defHttp.delete({
      url: `${Api.AddDict}?dictId=${id}`,
    });
  },
};

export default dictApi;
