import request from '@/utils/request'

// 查询红绿灯列表
export function listTrafficLight() {
  return request({
    url: '/traffic-light/devices/list',
    method: 'get'
  })
}

// 查询红绿灯详细
export function getTrafficLight(deviceId) {
  return request({
    url: '/traffic-light/devices/' + deviceId,
    method: 'get'
  })
}

// 修改红绿灯
export function updateTrafficLight(data) {
  const { deviceId, ...requestBody } = data;
  return request({
    url: `/traffic-light/devices/${deviceId}`,
    method: 'put',
    data: requestBody
  })
}

// 新增红绿灯
export function addTrafficLight(data) {
  return request({
    url: '/traffic-light/devices',
    method: 'post',
    data: data
  })
}

// 删除红绿灯
export function delTrafficLight(trafficLightId) {
  return request({
    url: '/road/trafficLight/' + trafficLightId,
    method: 'delete'
  })
}

// 设置设备状态
export function setTrafficLightStatus(deviceId, status) {
  return request({
    url: `/traffic-light/devices/${deviceId}/status`,
    method: 'patch',
    data: { status: status }
  })
}

// 检查设备可用性
export function checkTrafficLightAvailability(deviceId) {
  return request({
    url: `/traffic-light/devices/${deviceId}/availability`,
    method: 'get'
  })
}

// 获取设备统计
export function getTrafficLightStatistics() {
  return request({
    url: '/traffic-light/devices/statistics',
    method: 'get'
  })
}

// 搜索设备
export function searchTrafficLights(query) {
  return request({
    url: '/traffic-light/devices/search',
    method: 'get',
    params: query
  })
}

// 获取在线设备
export function getOnlineTrafficLights() {
  return request({
    url: '/traffic-light/devices/online',
    method: 'get'
  })
}

// 根据制造商查找设备
export function getTrafficLightsByManufacturer(manufacturer) {
  return request({
    url: `/traffic-light/devices/manufacturer/${manufacturer}`,
    method: 'get'
  })
}

// 获取所有设备
export function getAllTrafficLights() {
  return request({
    url: '/traffic-light/devices/list',
    method: 'get'
  })
}

// 根据路口获取设备
export function getTrafficLightsByIntersection(intersectionId) {
  return request({
    url: `/traffic-light/devices/intersection/${intersectionId}`,
    method: 'get'
  })
}

// 根据路口获取激活设备
export function getActiveTrafficLightsByIntersection(intersectionId) {
  return request({
    url: `/traffic-light/devices/intersection/${intersectionId}/active`,
    method: 'get'
  })
}

// 获取激活且在线的设备
export function getActiveOnlineTrafficLights() {
  return request({
    url: '/traffic-light/devices/active-online',
    method: 'get'
  })
}
