import request from '@/utils/request'

/**
 * 获取字典列表
 * @param {Object} params 查询参数
 * @returns {Promise}
 */
export function getDictionaryList(params) {
  return request({
    url: '/dictionaries',
    method: 'get',
    params
  })
}

/**
 * 获取字典详情
 * @param {string|number} id 字典ID
 * @returns {Promise}
 */
export function getDictionaryById(id) {
  return request({
    url: `/dictionaries/${id}`,
    method: 'get'
  })
}

/**
 * 根据字典编码和数据获取字典
 * @param {string} dictCode 字典编码
 * @param {string} dictData 字典数据
 * @returns {Promise}
 */
export function getDictionaryByCodeAndData(dictCode, dictData) {
  return request({
    url: `/dictionaries/code/${dictCode}/data/${dictData}`,
    method: 'get'
  })
}

/**
 * 根据字典名称获取字典数据
 * @param {string} dictName 字典名称
 * @returns {Promise}
 */
export function getDictionaryDataByName(dictName) {
  return request({
    url: `/dictionaries/name/${dictName}`,
    method: 'get'
  })
}

export function getDictionaryData(dictName) {
  return request({
    url: `/dictionaries/name/${dictName}`,
    method: 'get'
  })
}

/**
 * 创建字典
 * @param {Object} data 字典数据
 * @returns {Promise}
 */
export function createDictionary(data) {
  return request({
    url: '/dictionaries',
    method: 'post',
    data
  })
}

/**
 * 更新字典
 * @param {string|number} id 字典ID
 * @param {Object} data 字典数据
 * @returns {Promise}
 */
export function updateDictionary(id, data) {
  return request({
    url: `/dictionaries/${id}`,
    method: 'put',
    data
  })
}

/**
 * 删除字典
 * @param {string|number} id 字典ID
 * @returns {Promise}
 */
export function deleteDictionary(id) {
  return request({
    url: `/dictionaries/${id}`,
    method: 'delete'
  })
}

/**
 * 批量删除字典
 * @param {Array} ids 字典ID数组
 * @returns {Promise}
 */
export function batchDeleteDictionaries(ids) {
  return request({
    url: '/dictionaries/batch',
    method: 'delete',
    data: { ids }
  })
}