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

/** 获取机柜U位状态 */
export const fetchRackUnits = (rackId: number) => {
  return request.get(`/Assets/v1/unit/rack/${rackId}`);
};

/** 获取U位列表（别名） */
export const fetchUnitList = fetchRackUnits;

/** 分配U位 */
export const allocateUnit = (data: {
  rack_id: number;
  start_unit: number;
  occupied_units: number;
  asset_id?: number;
  asset_code?: string;
  asset_name: string;
  asset_type: string;
  power_consumption?: number;
  description?: string;
}) => {
  return request.post("/Assets/v1/unit/allocate", data);
};

/** 释放U位 */
export const releaseUnit = (data: {
  rack_id: number;
  start_unit: number;
  end_unit: number;
}) => {
  return request.post("/Assets/v1/unit/release", data);
};

/** 预留U位 */
export const reserveUnit = (data: {
  rack_id: number;
  start_unit: number;
  occupied_units: number;
  reserved_for: string;
  reserved_until: string;
  description?: string;
}) => {
  return request.post("/Assets/v1/unit/reserve", data);
};

/** 取消预留 */
export const cancelReservation = (data: {
  rack_id: number;
  start_unit: number;
  end_unit: number;
}) => {
  return request.post("/Assets/v1/unit/cancel_reservation", data);
};

/** 更新U位状态 */
export const updateUnitStatus = (data: {
  rack_id: number;
  start_unit: number;
  end_unit: number;
  status: "available" | "disabled";
}) => {
  return request.put("/Assets/v1/unit/status", data);
};
