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

export interface CameraShareType {
  id?: number; //唯一id
  cameraId?: number; //相机id  -1表示全部
  toTenantId?: number; //对应的公司id  发给谁  -1表示全部  -10表示自己
  permission?: string; //权限  0/1
  endTime?: string; //结束时间  有限期
  isAdd?: boolean; //是否添加     -1表示全部
  isDelete?: boolean; //是否删除
  creator?: string; //创建者
  createTime?: string; //创建时间
  remark?: string; //备注
  tenantId?: number; //谁发的相机共享
  connected?: boolean; //是否连接
  cameraIp?: string; //相机的ip地址
  cameraType?: string; //相机的协议类型
  cameraPort?: string; //端口地址
  tenantName?: string; //企业名称
  tenantCode?: string; //企业账号
  code?: string; //设备id
  workspaceName?: string; //车间场景;
  name?: string; //工位场景
  cameraName?: string; //可编辑的相机名称
  cameraCode?: string; //可编辑的相机设备id
  cameraWorkspace?: string; //可编辑的场景  id
  cameraWorkspaceName?: string; //可编辑的场景  name
  username?: string; //用户名
  password?: string; //密码
}

export interface CameraShareQueryType {
  pageNumber?: number;
  pageSize?: number;
  cameraId?: number;
  isAdd?: boolean | number;
  toTenantId?: number;
  tenantName?: string; //企业名称
  tenantCode?: string; //企业账号
}

export interface ReturnType {
  records: CameraShareType[];
  pageNumber?: number;
  pageSize?: number;
  totalPage?: boolean | number;
  totalRow: number;
}

/** 查询分享的相机*/
export const getShareCameraList = (params: CameraShareQueryType) => {
  return http.request<ReturnType>(
    {
      url: '/cameraTenant/getList',
      method: 'GET',
      params,
    },
    { isShowErrorMessage: false },
  );
};

/** 编辑分享的相机*/
export const editShareCameraList = (data: CameraShareType) => {
  return http.request<CameraShareType[]>({
    url: '/cameraTenant/update',
    method: 'put',
    data,
  });
};

/** 删除分享的相机*/
export const delShareCameraList = (id: number) => {
  return http.request<CameraShareType[]>({
    url: `/cameraTenant/delete?cameraToTenantId=${id}`,
    method: 'delete',
  });
};

/** 添加分享的相机*/
export const addShareCameraList = (data: CameraShareType) => {
  return http.request<CameraShareType[]>({
    url: '/cameraTenant/save',
    method: 'post',
    data: [data],
  });
};

interface VerifyReturn {
  tenantName: string;
  tenantId: number;
}

/** 验证*/
export const getVerify = (tenantCode: string) => {
  return http.request<VerifyReturn>({
    url: `/cameraTenant/check?tenantCode=${tenantCode}`,
    method: 'GET',
  });
};
