import request from './request'

// ==================== 字典类型 ====================

export interface SysDictType {
  id: number
  dictName: string
  dictType: string
  status: string
  remark: string | null
  createBy: string | null
  updateBy: string | null
  createdAt: string
  updatedAt: string
  deletedAt: string | null
}

export interface CreateDictTypeDto {
  dictName: string
  dictType: string
  status?: string
  remark?: string
}

export interface UpdateDictTypeDto {
  dictName?: string
  status?: string
  remark?: string
}

/** 获取所有字典类型 */
export function getAllDictTypes(): Promise<SysDictType[]> {
  return request.get('/api/dict/types')
}

/** 根据ID获取字典类型 */
export function getDictTypeById(id: number): Promise<SysDictType> {
  return request.get(`/api/dict/types/${id}`)
}

/** 根据类型编码获取字典类型 */
export function getDictTypeByType(dictType: string): Promise<SysDictType> {
  return request.get(`/api/dict/types/type/${dictType}`)
}

/** 创建字典类型 */
export function createDictType(data: CreateDictTypeDto): Promise<SysDictType> {
  return request.post('/api/dict/types', data)
}

/** 更新字典类型 */
export function updateDictType(id: number, data: UpdateDictTypeDto): Promise<SysDictType> {
  return request.put(`/api/dict/types/${id}`, data)
}

/** 删除字典类型 */
export function deleteDictType(id: number): Promise<void> {
  return request.delete(`/api/dict/types/${id}`)
}

// ==================== 字典数据 ====================

export interface SysDictData {
  id: number
  dictSort: number
  dictLabel: string
  dictValue: string
  dictType: string
  cssClass: string | null
  listClass: string | null
  isDefault: string
  status: string
  createBy: string | null
  updateBy: string | null
  createdAt: string
  updatedAt: string
  deletedAt: string | null
}

export interface CreateDictDataDto {
  dictSort?: number
  dictLabel: string
  dictValue: string
  dictType: string
  cssClass?: string
  listClass?: string
  isDefault?: string
  status?: string
}

export interface UpdateDictDataDto {
  dictSort?: number
  dictLabel?: string
  dictValue?: string
  cssClass?: string
  listClass?: string
  isDefault?: string
  status?: string
}

/** 获取所有字典数据 */
export function getAllDictData(): Promise<SysDictData[]> {
  return request.get('/api/dict/data')
}

/** 根据类型获取字典数据 */
export function getDictDataByType(dictType: string): Promise<SysDictData[]> {
  return request.get(`/api/dict/data/type/${dictType}`)
}

/** 根据ID获取字典数据 */
export function getDictDataById(id: number): Promise<SysDictData> {
  return request.get(`/api/dict/data/${id}`)
}

/** 创建字典数据 */
export function createDictData(data: CreateDictDataDto): Promise<SysDictData> {
  return request.post('/api/dict/data', data)
}

/** 更新字典数据 */
export function updateDictData(id: number, data: UpdateDictDataDto): Promise<SysDictData> {
  return request.put(`/api/dict/data/${id}`, data)
}

/** 删除字典数据 */
export function deleteDictData(id: number): Promise<void> {
  return request.delete(`/api/dict/data/${id}`)
}
