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

/** 相机树的结点类型 */
export enum CameraTreeNodeType {
  /** 公司 */
  company = 'company',
  /** 车间 */
  workshop = 'workshop',
  /** 工位 */
  workspace = 'workspace',
  /** 相机 */
  camera = 'camera',
}

export interface UpdateCameraAlgoParam {
  id: number;
  algoId: number;
  cameraId: number;
  status: 0 | 1;
}

export interface CameraTree {
  id: number;
  name: string;
  code: string;
  children: CameraTree[];
  nodeType: CameraTreeNodeType;
  pushstreamIp: string;
  integrationState: number;
}

export interface UpdateAlgoStatusBatchParam {
  cameraId: number;
  algoIds: number[];
  status: 0 | 1;
}

/** 获取摄像头所在的树状结构 */
export const getCameraTree = () => {
  return http.request<CameraTree[]>(
    {
      url: '/camera/queryAllOwnedCameraTree',
      method: 'get',
    },
    { ignoreTargetTenantId: true },
  );
};

/** 更新相机的某个算法是否开启 */
export const updateCameraAlgoApi = (data: UpdateCameraAlgoParam) => {
  return http.request(
    {
      url: '/algo/updateCameraAlgoRel',
      method: 'post',
      data,
    },
    {
      isShowErrorMessage: true,
    },
  );
};

/** 更新相机的算法列表是否开启 */
export const updateAlgoStatusBatchApi = (data: UpdateAlgoStatusBatchParam) => {
  return http.request(
    {
      url: '/algo/updateAlgoStatusBatch',
      method: 'post',
      data,
    },
    {
      isShowErrorMessage: true,
    },
  );
};
