import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import {
  DictQuery,
  DictPageResult,
  DictTypeForm,
  DictItemQuery,
  DictItemPageResult,
  DictItemForm
} from './types';
// 查询字典
export function getTreelist(params:any) {
  return request({
    url: '/system/dictionary/dictList',
    method: 'get',
    params: params
  });
}

// 新增字典
export function addDict(params:any) {
  return request({
    url: '/system/dictionary/addDict',
    method: 'post',
    data: params
  });
}

// 修改字典
export function updateDict(params:any) {
  return request({
    url: '/system/dictionary/updateDict',
    method: 'post',
    data: params
  });
}
// 删除字典
export function deleteById(params:any) {
  return request({
    url: '/system/dictionary/deleteById',
    method: 'post',
    params: params
  });
}
// 字典排序
export function changeDictOrder(params:any) {
  return request({
    url: '/system/dictionary/changeDictOrder',
    method: 'post',
    params: params
  });
}
// 查询字典项
export function getDictItemById(params:any) {
  return request({
    url: '/system/dictionaryItems/page',
    method: 'get',
    params: params
  });
}

// 新增字典项
export function addDictionaryItem(params:any) {
  return request({
    url: '/system/dictionaryItems/addDictionaryItem',
    method: 'post',
    data: params
  });
}

// 修改字典项
export function updateDictionaryItem(params:any) {
  return request({
    url: '/system/dictionaryItems/updateDictionaryItem',
    method: 'post',
    data: params
  });
}
// 删除字典项
export function deleteDictItemById(params:any) {
  return request({
    url: '/system/dictionaryItems/deleteDictItemById',
    method: 'post',
    params: params
  });
}
// 批量删除字典项
export function deleteDictItemByIds(params:any) {
  return request({
    url: '/system/dictionaryItems/deleteDictItemByIds',
    method: 'post',
    params: params
  });
}

// 字典项排序
export function changeItemOrder(params:any) {
  return request({
    url: '/system/dictionaryItems/changeItemOrder',
    method: 'post',
    params: params
  });
}
/**
 * 获取字典类型分页列表
 *
 * @param queryParams
 */
export function listDictTypePages(
  queryParams: DictQuery
): AxiosPromise<DictPageResult> {
  return request({
    url: '/api/v1/dict/types/pages',
    method: 'get',
    params: queryParams
  });
}

/**
 * 获取字典类型表单数据
 *
 * @param id
 */
export function getDictTypeForm(id: number): AxiosPromise<DictTypeForm> {
  return request({
    url: '/api/v1/dict/types/' + id + '/form',
    method: 'get'
  });
}

/**
 * 新增字典类型
 *
 * @param data
 */
export function addDictType(data: DictTypeForm) {
  return request({
    url: '/api/v1/dict/types',
    method: 'post',
    data: data
  });
}

/**
 * 修改字典类型
 *
 * @param id
 * @param data
 */
export function updateDictType(id: number, data: DictTypeForm) {
  return request({
    url: '/api/v1/dict/types/' + id,
    method: 'put',
    data: data
  });
}

/**
 * 删除字典类型
 */
export function deleteDictTypes(ids: string) {
  return request({
    url: '/api/v1/dict/types/' + ids,
    method: 'delete'
  });
}

/**
 * 获取字典类型的数据项
 *
 * @param typeCode 字典类型编码
 */
export function getDictionaries(typeCode: string): AxiosPromise<OptionType[]> {
  return request({
    url: '/api/v1/dict/types/' + typeCode + '/items',
    method: 'get'
  });
}

/**
 * 获取字典项分页列表
 */
export function listDictItemPages(
  queryParams: DictItemQuery
): AxiosPromise<DictItemPageResult> {
  return request({
    url: '/api/v1/dict/items/pages',
    method: 'get',
    params: queryParams
  });
}

/**
 * 获取字典数据项表单数据
 *
 * @param id
 */
export function getDictItemData(id: number): AxiosPromise<DictItemForm> {
  return request({
    url: '/api/v1/dict/items/' + id + '/form',
    method: 'get'
  });
}

/**
 * 新增字典项
 *
 * @param data
 */
export function saveDictItem(data: DictItemForm) {
  return request({
    url: '/api/v1/dict/items',
    method: 'post',
    data: data
  });
}

/**
 * 修改字典项
 *
 * @param id
 * @param data
 */
export function updateDictItem(id: number, data: DictItemForm) {
  return request({
    url: '/api/v1/dict/items/' + id,
    method: 'put',
    data: data
  });
}

/**
 * 批量删除字典数据项
 *
 * @param ids 字典项ID，多个以英文逗号(,)分割
 */
export function deleteDictItems(ids: string) {
  return request({
    url: '/api/v1/dict/items/' + ids,
    method: 'delete'
  });
}
// 查询字典项
export function getDictItemByCode(params:any) {
  return request({
    url: '/system/dictionaryItems/list',
    method: 'post',
    params:params
  });
}

