import request from '@/utils/request'
import type { 
  DictionaryPageRequest, 
  DictionaryCreateRequest, 
  DictionaryUpdateRequest,
  Dictionary 
} from '@/types/dictionary'
import type { ApiResponse, PageResult } from '@/types/common'

// 分页查询字典
export function getDictionaryPage(params: DictionaryPageRequest) {
  return request<ApiResponse<PageResult<Dictionary>>>({
    url: '/dictionary/list',
    method: 'get',
    params
  })
}

// 根据ID获取字典详情
export function getDictionaryById(id: string) {
  return request<ApiResponse<Dictionary>>({
    url: '/dictionary/detail',
    method: 'get',
    params: { id }
  })
}

// 创建字典
export function createDictionary(data: DictionaryCreateRequest) {
  return request<ApiResponse<Dictionary>>({
    url: '/dictionary',
    method: 'post',
    data
  })
}

// 更新字典
export function updateDictionary(data: DictionaryUpdateRequest) {
  return request<ApiResponse<Dictionary>>({
    url: '/dictionary',
    method: 'put',
    data
  })
}

// 删除字典
export function deleteDictionary(id: string) {
  return request<ApiResponse<void>>({
    url: '/dictionary/delete',
    method: 'delete',
    params: { id }
  })
}

// 根据字典类型查询字典集合
export function getDictionariesByType(dictType: string) {
  return request<ApiResponse<Dictionary[]>>({
    url: '/dictionary/byType',
    method: 'get',
    params: { dictType }
  })
}

// 根据字典类型查询启用的字典集合
export function getEnabledDictionariesByType(dictType: string) {
  return request<ApiResponse<Dictionary[]>>({
    url: '/dictionary/enabledByType',
    method: 'get',
    params: { dictType }
  })
}