import { request } from '@/api/request'

/** 获取所有已启用数据中心（下拉，不分页） */
export const fetchDatacenterAll = (params?: { keyword?: string }) => {
  return request.get('/Assets/v1/datacenter/all', { params })
}

/** 获取数据中心列表（分页） */
export const fetchDatacenterList = (data?: {
  page?: number
  page_size?: number
  keyword?: string
  province_id?: number
  city_id?: number
  status?: string
}) => {
  return request.post('/Assets/v1/datacenter/list', data || {})
}

/** 获取数据中心详情 */
export const fetchDatacenterDetail = (id: number) => {
  return request.get(`/Assets/v1/datacenter/detail/${id}`)
}

/** 创建数据中心 */
export const createDatacenter = (data: any) => {
  return request.post('/Assets/v1/datacenter/create', data)
}

/** 批量导入数据中心 */
export const bulkImportDatacenters = (data: { dry_run?: boolean; items: any[] }) => {
  return request.post('/Assets/v1/datacenter/bulk_import', data)
}

/** 更新数据中心 */
export const updateDatacenter = (data: any) => {
  return request.put('/Assets/v1/datacenter/update', data)
}

/** 删除数据中心 */
export const deleteDatacenter = (id: number) => {
  return request.delete(`/Assets/v1/datacenter/delete/${id}`)
}

/** 获取省份列表（用于下拉选择） */
export const fetchProvinceList = (params?: { keyword?: string }) => {
  return request.get('/Assets/v1/province/all', { params })
}

/** 获取城市列表（用于下拉选择） */
export const fetchCityList = (provinceId: number, params?: { keyword?: string }) => {
  return request.get(`/Assets/v1/city/province/${provinceId}`, { params })
}

/** 根据城市获取数据中心列表 */
export const fetchDatacenterByCity = (cityId: number) => {
  return request.get(`/Assets/v1/datacenter/city/${cityId}`)
}

/** 获取数据中心树形结构 */
export const fetchDatacenterTree = () => {
  return request.get('/Assets/v1/datacenter/tree')
}
