import request from '@/utils/request'
// 查询路口列表
// 修改URL为标准的列表查询路径
export function listIntersection() {
  return request({
    url: '/traffic-light/intersections/list',  // 修改URL
    method: 'get',
  });
}
export function getIntersectionname(query) {
  return request({
    url: '/traffic-light/intersections/search',
    method: 'get',
    params: query
  });
}
// 查询路口详细
export function getIntersection(intersectionId) {
  return request({
    url: `/traffic-light/intersections/${intersectionId}`,
    method: 'get'
  }).then(response => {
    console.log('获取路口详情成功:', response);
    return response;
  }).catch(error => {
    console.error('获取路口详情失败:', error);
    throw error;
  });
}

// 新增路口
export function addIntersection(data) {
  return request({
    url: '/traffic-light/intersections',
    method: 'post',
    data: data
  }).then(response => {
    console.log('新增路口成功:', response);
    return response;
  }).catch(error => {
    console.error('新增路口失败:', error);
    throw error;
  });
}

// 修改路口
export function updateIntersection(intersectionId, data) {
  return request({
    url: `/traffic-light/intersections/${intersectionId}`,
    method: 'put',
    data: data
  }).then(response => {
    console.log('修改路口成功:', response);
    return response;
  }).catch(error => {
    console.error('修改路口失败:', error);
    throw error;
  });
}

// // 删除路口
// export function delIntersection(intersectionId) {
//   return request({
//     url: `/traffic-light/intersections/${intersectionId}`,
//     method: 'delete'
//   }).then(response => {
//     console.log('删除路口成功:', response);
//     return response;
//   }).catch(error => {
//     console.error('删除路口失败:', error);
//     throw error;
//   });
// }

// 获取路口统计数据
export function getIntersectionStatistics() {
  return request({
    url: '/traffic-light/intersections/statistics',
    method: 'get'
  }).then(response => {
    console.log('获取路口统计数据成功:', response);
    return response;
  }).catch(error => {
    console.error('获取路口统计数据失败:', error);
    throw error;
  });
}
