import request from "@/utils/request";

// 管网基础信息
export function listPipeNetwork(query) {
  return request({
    url: "/PipeNetworkBase/findByPage",
    method: "get",
    params: query
  });
}

export function getPipeNetwork(id) {
  return request({
    url: `/PipeNetworkBase/getById/${id}`,
    method: "get"
  });
}

export function listPipeNetworkAll() {
  return request({
    url: "/PipeNetworkBase/getList",
    method: "get"
  });
}

export function addPipeNetwork(data) {
  return request({
    url: "/PipeNetworkBase/save",
    method: "post",
    data
  });
}

export function updatePipeNetwork(data) {
  return request({
    url: "/PipeNetworkBase/updateById",
    method: "put",
    data
  });
}

export function delPipeNetwork(id) {
  return request({
    url: "/PipeNetworkBase/deleteById",
    method: "delete",
    params: { id }
  });
}

// 关键监测点
export function listMonitorPoint(query) {
  return request({
    url: "/MonitorPoint/findByPage",
    method: "get",
    params: query
  });
}

export function getMonitorPoint(id) {
  return request({
    url: `/MonitorPoint/getById/${id}`,
    method: "get"
  });
}

export function listMonitorPointAll() {
  return request({
    url: "/MonitorPoint/getList",
    method: "get"
  });
}

export function addMonitorPoint(data) {
  return request({
    url: "/MonitorPoint/save",
    method: "post",
    data
  });
}

export function updateMonitorPoint(data) {
  return request({
    url: "/MonitorPoint/updateById",
    method: "put",
    data
  });
}

export function delMonitorPoint(id) {
  return request({
    url: "/MonitorPoint/deleteById",
    method: "delete",
    params: { id }
  });
}

export function getMonitorPointDetail(pointId) {
  return request({
    url: `/MonitorPoint/pointDetail/${pointId}`,
    method: "get"
  });
}

export function listPointsByNetwork(networkId) {
  return request({
    url: `/MonitorPoint/byNetwork/${networkId}`,
    method: "get"
  });
}

export function bindPointEquipment(pointId, equipmentIds) {
  return request({
    url: "/MonitorPoint/bindEquipment",
    method: "post",
    params: {
      pointId,
      equipmentIds: Array.isArray(equipmentIds) ? equipmentIds.join(",") : equipmentIds
    }
  });
}

export function unbindPointEquipment(pointId, equipmentIds) {
  return request({
    url: "/MonitorPoint/unbindEquipment",
    method: "post",
    params: {
      pointId,
      equipmentIds: Array.isArray(equipmentIds) ? equipmentIds.join(",") : equipmentIds
    }
  });
}

// 物联感知设备
export function listEquipment(query) {
  return request({
    url: "/EquipmentBase/findByPage",
    method: "get",
    params: query
  });
}

export function getEquipment(id) {
  return request({
    url: `/EquipmentBase/getById/${id}`,
    method: "get"
  });
}

export function addEquipment(data) {
  return request({
    url: "/EquipmentBase/save",
    method: "post",
    data
  });
}

export function updateEquipment(data) {
  return request({
    url: "/EquipmentBase/updateById",
    method: "put",
    data
  });
}

export function delEquipment(id) {
  return request({
    url: "/EquipmentBase/deleteById",
    method: "delete",
    params: { id }
  });
}

export function getEquipmentDetail(equipmentId) {
  return request({
    url: `/EquipmentBase/detail/${equipmentId}`,
    method: "get"
  });
}

export function listEquipmentByPoint(pointId) {
  return request({
    url: `/EquipmentBase/byPoint/${pointId}`,
    method: "get"
  });
}

export function updateEquipmentStatus(equipmentId, currentStatus) {
  return request({
    url: "/EquipmentBase/updateStatus",
    method: "put",
    params: { equipmentId, currentStatus }
  });
}

export function testEquipment(equipmentId, payload = {}) {
  return request({
    url: "/EquipmentBase/test",
    method: "post",
    params: {
      equipmentId,
      testType: payload.testType,
      testDetail: payload.testDetail,
      testUser: payload.testUser
    }
  });
}

// 基础辅助数据
export function listEquipmentTypeAll() {
  return request({
    url: "/EquipmentType/getList",
    method: "get"
  });
}

export function listEquipmentStatusAll() {
  return request({
    url: "/EquipmentStatus/getList",
    method: "get"
  });
}
