import { request } from "@/api/request";

/** 获取楼层列表（分页） */
export const fetchFloorList = (data?: {
  page?: number;
  page_size?: number;
  keyword?: string;
  datacenter_id?: number;
  status?: string;
}) => {
  return request.post("/Assets/v1/floor/list", data || {});
};

/** 获取楼层详情 */
export const fetchFloorDetail = (id: number) => {
  return request.get(`/Assets/v1/floor/detail/${id}`);
};

/** 根据数据中心获取楼层列表（下拉，不分页） */
export const fetchFloorListByDatacenter = (
  datacenterId: number,
  params?: { name?: string }
) => {
  return request.get(`/Assets/v1/floor/datacenter/${datacenterId}`, { params });
};

/** 创建楼层 */
export const createFloor = (data: any) => {
  return request.post("/Assets/v1/floor/create", data);
};

/** 更新楼层 */
export const updateFloor = (data: any) => {
  return request.put("/Assets/v1/floor/update", data);
};

/** 删除楼层 */
export const deleteFloor = (id: number) => {
  return request.delete(`/Assets/v1/floor/delete/${id}`);
};

/** 获取数据中心列表（用于下拉选择） */
export const fetchDatacenterList = (params?: { keyword?: string; name?: string }) => {
  const normalizedParams = params?.keyword
    ? { ...params, name: params.name ?? params.keyword }
    : params
  return request.get("/Assets/v1/datacenter/all", { params: normalizedParams });
};
