import { http } from '@/utils/http/axios';

export function editTenant(data) {
  return http.request({
    url: '/tenant/update',
    method: 'post',
    data,
  });
}

export function queryCameraGroupList(type: number) {
  //是否主页展示：0-否 1-是
  return http.request({
    url: `/cameraGroup/queryCameraGroupList?type=${type}`,
    method: 'get',
  });
}

export function addCameraGroupApi(data: { groupName: string }) {
  return http.request({
    url: '/cameraGroup/addCameraGroup',
    method: 'post',
    data,
  });
}

export function deleteCameraGroupApi(cameraGroupId: number) {
  return http.request({
    url: `/cameraGroup/deleteCameraGroup?cameraGroupId=${cameraGroupId}`,
    method: 'delete',
  });
}

export function addCameraIntoGroupApi(data: { cameraId: number; groupId: number; orderNum: number }) {
  return http.request({
    url: '/cameraGroup/saveCamera2Group',
    method: 'post',
    data,
  });
}

export function deleteCameraFromGroupApi(data: {
  // cameraGroupDetailId: number;
  groupId: number;
  cameraId: number;
}) {
  return http.request({
    // url: "/cameraGroup/deleteCameraFromGroup",
    url: `/cameraGroup/deleteCameraFromGroup?groupId=${data.groupId}&cameraId=${data.cameraId}`,
    method: 'delete',
  });
}

export function modifyCameraGroupApi(data: {
  groupId: number;
  groupName?: string;
  isDefault?: number;
  playIntervalSec?: number;
  isPaused?: number;
}) {
  return http.request({
    url: '/cameraGroup/updateCameraGroup',
    method: 'post',
    data,
  });
}

interface UpdateCameraOrderParam {
  groupId: number;
  cameraId: number;
  orderNum: number;
}

/**
 * 修改相机的顺序
 */
export function updateCameraOrderApi(data: UpdateCameraOrderParam[]) {
  return http.request({
    url: '/cameraGroup/updateCameraOrder',
    method: 'post',
    data,
  });
}

/**
 * 保存或更新相机组
 */
export function saveOrUpdateCameraGroupAllApi(data) {
  return http.request({
    url: '/cameraGroup/saveOrUpdateCameraGroupAll',
    method: 'post',
    data,
  });
}

/**
 * 查询相机组列表
 */
export function queryCameraGroupListByTypeAndSourceIdApi(data) {
  return http.request({
    url: '/cameraGroup/queryCameraGroupListByTypeAndSourceId',  
    method: 'post',
    data,
  });
}
