import {
  getListByUser,
  axios,
  PaggingReq,
  PaggingRes,
  getCameraList,
  unbindCamera,
  insertCamera,
  updateCamera,
} from "@/request";

export enum CameraType {
  SWKK_OLD = 0,
  SWKK = 1,
  SWKK_L = 2,
  SWKK_LA = 5,
  SWKJ = 9,
  SWSS1 = 10,
  SWSS2 = 11,
}

export type Camera = {
  id: string;
  cameraType: CameraType;
  snCode: string;
  deptId: string;
  userId: string;
  deptName?: string;
  usedSpaceStr?: string;
  nickName?: string;
};

// 选择用户相机用
export const getCameras = async (): Promise<Camera[]> => {
  const res = await axios.get(getListByUser);
  return res.data;
};

type CamerasPaggingParams = PaggingReq<
  Pick<Camera, "snCode" | "deptId"> & {
    type: string;
    searchKey: string;
  }
>;
export const getCameraPagging = async (params: CamerasPaggingParams) =>
  (await axios.get(getCameraList, { params })).data as PaggingRes<Camera>;

export const delCamera = (camera: Camera) =>
  axios.post(unbindCamera, { cameraSn: camera.snCode });

export const addCamera = (camera: Camera) =>
  axios.post(insertCamera, { ...camera, cameraSn: camera.snCode });

export const editCamera = (camera: Camera) =>
  axios.post(updateCamera, { ...camera, cameraSn: camera.snCode });
