import http from '@/api'
import {
  ReqDictionaryList,
  ReqEditDictData,
  ReqId,
  ReqSaveDictionary,
  ResDictionary,
  ResDictionaryCategory
} from '@/api/interface/dectionory/index'

const api = {
  getDectionoryList: '/platform/dict/dectionoryList', // 字典列表
  postEditDictData: '/platform/dict/editDictData', // 编辑字典值
  postEditDictionary: '/platform/dict/editDictionary', // 编辑字典
  postEnableDictionary: '/platform/dict/enableDictionary', // 启用字典
  postDisableDictionary: '/platform/dict/disableDictionary', // 停用字典
  getGetDictCateItem: '/platform/dict/getDictCateItem', // 查询字典大类
  getGetDictDataInfo: '/platform/dict/getDictDataInfo', // 查询管理子集详情
  postRemoveDictData: '/platform/dict/removeDictData', // 删除字典值
  postRemoveDictionary: '/platform/dict/removeDictionary', // 删除字典
  postSaveDictData: '/platform/dict/saveDictData', // 新增字典值
  postSaveDictionary: '/platform/dict/saveDictionary', // 新增字典
  getGetDictDataList: '/platform/dict/getDictDataList', // 查询管理子集列表
  getGetDictDataByName: '/platform/dict/getDictDataByName', // 根据字典名字查询字典值
  dectionoryPostSort: '/platform/dict/sort' // 字典值排序
}

/**
 * @description 字典列表
 * @author 邹琪涛
 * @docs http://api.seevin.com/project/669/interface/api/33136
 * @param page 页码  [必填]
 * @param limit 每页数量（默认为10）
 * @param categoryNameOrDictName 字典大类名称或者字典名称
 * @param isAllowAddsub 是否允许新增子集 1允许 0不允许
 * @param isAllowEdit 是否允许编辑 1允许 0不允许
 * @param isAllowDelete 是否允许删除 1允许 0不允许
 * @param status 状态 1编辑中 2启用 3停用
 */
export const getDectionoryList = (params: ReqDictionaryList) => {
  return http.get<ResDictionary[]>(api.getDectionoryList, params)
}

/**
 * @description 编辑字典值
 * @author 邹琪涛
 * @docs http://api.seevin.com/project/669/interface/api/33138
 * @param dataCode 值编码
 * @param dictDataId 字典值id
 * @param dictId 字典id
 * @param remark 备注
 * @param valueName 字典值名称
 */
export const postEditDictData = (data: ReqEditDictData) => {
  return http.post(api.postEditDictData, data)
}

/**
 * @description 编辑字典
 * @author 邹琪涛
 * @docs http://api.seevin.com/project/669/interface/api/33139
 * @param categoryId 字典大类
 * @param dictCode 字典编码
 * @param dictId id
 * @param dictName 字典名称
 * @param isAllowAddsub 是否允许添加子集:1允许,0不允许
 * @param isAllowDelete 是否允许删除:1允许,0不允许
 * @param isAllowEdit 是否允许编辑:1允许,0不允许
 * @param remark 字典说明
 */
export const postEditDictionary = (data: ReqSaveDictionary) => {
  return http.post(api.postEditDictionary, data)
}

/**
 * @description 启用字典
 * @author 邹琪涛
 * @docs http://api.seevin.com/project/669/interface/api/33140
 * @param dictId undefined
 */
export const postEnableDictionary = (data: ReqId) => {
  return http.post(api.postEnableDictionary, data, { noLoading: false })
}

/**
 * @description 查询字典大类
 * @author 邹琪涛
 * @docs http://api.seevin.com/project/669/interface/api/33141
 */
export const getGetDictCateItem = () => {
  return http.get<ResDictionaryCategory[]>(api.getGetDictCateItem, { noLoading: true })
}

/**
 * @description 查询管理子集详情
 * @author 邹琪涛
 * @docs http://api.seevin.com/project/669/interface/api/33142
 * @param dictId undefined
 */
export const getGetDictDataInfo = (params: ReqId) => {
  return http.get<ResDictionary>(api.getGetDictDataInfo, params)
}

/**
 * @description 删除字典值
 * @author 邹琪涛
 * @docs http://api.seevin.com/project/669/interface/api/33144
 * @param dictDataId undefined
 */
export const postRemoveDictData = (data: ReqId) => {
  return http.post(api.postRemoveDictData, data, { noLoading: true })
}

/**
 * @description 删除字典
 * @author 邹琪涛
 * @docs http://api.seevin.com/project/669/interface/api/33145
 * @param dictId undefined
 */
export const postRemoveDictionary = (data: ReqId) => {
  return http.post(api.postRemoveDictionary, data, { noLoading: true })
}

/**
 * @description 新增字典值
 * @author 邹琪涛
 * @docs http://api.seevin.com/project/669/interface/api/33146
 * @param dataCode 值编码
 * @param dictId 字典id
 * @param remark 备注
 * @param valueName 字典值名称
 */
export const postSaveDictData = (data: ReqEditDictData) => {
  return http.post(api.postSaveDictData, data)
}
/**
 * @description 新增字典
 * @author 邹琪涛
 * @docs http://api.seevin.com/project/669/interface/api/33147
 * @param categoryId 字典大类
 * @param dictCode 字典编码
 * @param dictName 字典名称
 * @param isAllowAddsub 是否允许添加子集:1允许,0不允许
 * @param isAllowDelete 是否允许删除:1允许,0不允许
 * @param isAllowEdit 是否允许编辑:1允许,0不允许
 * @param remark 字典说明
 */
export const postSaveDictionary = (data: ReqSaveDictionary) => {
  return http.post(api.postSaveDictionary, data)
}

/**
 * @description 查询管理子集列表
 * @author 邹琪涛
 * @docs http://api.seevin.com/project/669/interface/api/33153
 * @param dictId undefined
 */
export const getGetDictDataList = (params: ReqId) => {
  return http.get<ResDictionary[]>(api.getGetDictDataList, params, { noLoading: true })
}

/**
 * @description 根据字典名字查询字典值
 * @author 邹琪涛
 * @docs http://api.seevin.com/project/669/interface/api/33166
 */
export const getGetDictDataByName = (params: { dictName: string }) => {
  return http.get<ResDictionary[]>(api.getGetDictDataByName, params, { noLoading: true })
}

/**
 * @description 字典值排序
 * @author 邹琪涛
 * @docs http://api.seevin.com/project/669/interface/api/33167
 * @param dictDataId 字典值id
 * @param newSortNum 该菜单排序后的排序号 [必填]
 */
export const dectionoryPostSort = (data: { dictDataId: number | string; newSortNum: number }) => {
  return http.post(api.dectionoryPostSort, data)
}

/**
 * @description 停用字典
 * @author 邹琪涛
 * @docs http://api.seevin.com/project/669/interface/api/33137
 * @param dictId undefined
 */
export const postDisableDictionary = (data: ReqId) => {
  return http.post(api.postDisableDictionary, data, { noLoading: false })
}
