import { CameraDetailServer } from './cameraType';
import { IS_DISABLED } from '@/types/common/constants';
import { http } from '@/utils/http/axios';

export interface CameraStatusDetail {
  id: number;
  code: string;
  integrationState: IS_DISABLED;
  networkingState: IS_DISABLED;
}

/** 获取相机状态 */
export const getCameraState = (data: { cameraCodeList: string[] }) => {
  return http.request<CameraStatusDetail[]>(
    {
      url: '/camera/queryCameraStatusListByCameraCodes',
      method: 'post',
      data,
    },
    { ignoreTargetTenantId: true },
  );
};

export const getCameraInfoDetail = (param: string) => {
  return http.request<CameraDetailServer>({
    url: `/camera/queryCameraWithDetail?cameraCode=${param}`,
    method: 'get',
  });
};

interface FenceType {
  algoCode: string;
  algoId: number;
  cameraCode: string;
  cameraId: number;
  electronicFencePolygon: string;
  presetToken: string;
}

// 获取相机电子围栏
export const getCameraFence = (cameraId: number) => {
  return http.request<FenceType[]>({
    url: `/algo/queryCameraPreset?cameraId=${cameraId}`,
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    method: 'get',
  });
};

// 根据相机查询对应NVR
export const getNVRByCamera = (cameraId: number) => {
  return http.request(
    {
      url: `/nvr/findNvrByCamera?cameraId=${cameraId}`,
      method: 'get',
    },
    { isShowMessage: false, isShowErrorMessage: false },
  );
};

/** 根据相机id查询相机详情 */
export function queryCameraDetailById(cameraId: number): Promise<CameraDetailServer> {
  return http.request({
    url: `/admin/cameraPreview/queryCameraDetailById?id=${cameraId}`,
    method: 'post',
  });
}

/** 根据相机code查询相机详情 */
export function queryCameraDetailByCode(cameraCode: number): Promise<CameraDetailServer> {
  return http.request({
    url: `/admin/cameraPreview/queryCameraDetailById?id=${cameraCode}`,
    method: 'post',
  });
}
