import { http } from '@/utils/http/axios';
import { GetCameraGroupListRes } from '@/api/disaster-overview';
import type { QueryPageRequest, QueryPageResponse } from '@/types/basic-query';

/**
 * @description: 查询治安重点部位
 */
export interface GetPositionListParams {
  groupName: string; // 部位名称
  cameraName: string; // 相机名称
}

export interface PositionMonitorCameraListRes extends GetCameraGroupListRes {
  orderNum: number; // 排序序号
  createdAt: string; // 创建时间
  updatedAt: string; // 更新时间
}
export const getSecurityPositionList = (data: GetPositionListParams) => {
  return http.request({
    url: '/cameraGroup/queryHighSecurityAreas',
    method: 'post',
    data,
  });
};

/**
 * @description: 查询保密要害部位
 */
export const getConfidentialityPositionList = (data: GetPositionListParams) => {
  return http.request({
    url: '/cameraGroup/queryConfidentialKeyAreas',
    method: 'post',
    data,
  });
};

/**
 * @description: 新增或编辑治安重点部位/保密要害部位/院区重点监控区域
 */
export interface AddOrUpdatePositionInfoParams {
  id?: number; // 分组id
  groupName: string; // 分组名称
  type?: number; // 类型：3-治安重点部位，4-保密要害部位，5-院区重点监控区域
  cameraIdList?: number[]; // 相机id列表
}
export const addOrUpdatePositionInfo = (data: AddOrUpdatePositionInfoParams) => {
  return http.request({
    url: '/cameraGroup/saveOrUpdateCameraGroup',
    method: 'post',
    data,
  });
};

/**
 * @description: 删除治安重点部位/保密要害部位——deleteCameraGroupApi（/api/nine-square-grid/index.ts)
 */

/**
 * @description: 修改相机分组顺序
 */
export interface UpdateCameraGroupOrderParam {
  id: number; // 分组id
  orderNum: number; // 排序序号
}
export const updateCameraGroupOrder = (data: UpdateCameraGroupOrderParam[]) => {
  return http.request({
    url: '/cameraGroup/updateCameraGroupOrder',
    method: 'post',
    data,
  });
};

/**
 * @description: 保密要害部位--监测记录--分页查询入侵抓拍记录
 */
export interface QueryInvasionSnapshotParams {
  location?: string; // 地点
  startTime?: string; // 开始时间
  endTime?: string; // 结束时间
}
export interface QueryInvasionSnapshotRes {
  id: number; // 自增主键
  event: string; // 事件
  location: string; // 抓拍地点
  pictures: string; // 抓拍图片
  eventTime: string; // 抓拍时间
  createdAt: string; // 创建时间
  updatedAt: string; // 更新时间
  isDeleted: number; // 是否删除：0-是，大于0-否
}
export const getInvasionSnapshotList = (data: QueryPageRequest<QueryInvasionSnapshotParams>) => {
  return http.request<QueryPageResponse<QueryInvasionSnapshotRes>>({
    url: '/detectRecord/queryIntrusionCaptureRecordPage',
    method: 'post',
    data,
  });
};

/**
 * @description: 保密要害部位--监测记录--查询抓拍开关
 */
export const getInvasionSnapshotSwitch = () => {
  return http.request({
    url: '/detectRecord/querySnapshotSwitch',
    method: 'get',
  });
};

/**
 * @description: 保密要害部位--监测记录--更新抓拍开关
 */
export const updateInvasionSnapshotSwitch = (data: { switchStatus: boolean }) => {
  return http.request({
    url: '/detectRecord/updateSnapshotSwitch',
    method: 'post',
    data,
  });
};

/**
 * @description: 保密要害部位--监测记录--分页查询门禁记录
 */
export interface QueryAccessRecordParams {
  username?: string; // 姓名
  cardNum?: string; // 卡号
  deptName?: string; // 部门名称
  location?: string; // 进出地点
  startTime?: string; // 开始时间
  endTime?: string; // 结束时间
}
export interface QueryAccessRecordRes {
  id: number; // 自增主键
  username: string; // 姓名
  cardNum: string; // 卡号
  deptName: string; // 部门名称
  event: string; // 事件
  location: string; // 进出地点
  eventTime: string; // 进出时间
  createdAt: string; // 创建时间
  updatedAt: string; // 更新时间
  isDeleted: number; // 是否删除：0-是，大于0-否
}
export const getAccessRecordList = (data: QueryPageRequest<QueryAccessRecordParams>) => {
  return http.request<QueryPageResponse<QueryAccessRecordRes>>({
    url: '/detectRecord/queryAccessControlRecordPage',
    method: 'post',
    data,
  });
};

/**
 * @description: 保密要害部位--监测记录--导出入侵抓拍记录
 */
export const exportInvasionSnapshot = (data: QueryInvasionSnapshotParams) => {
  return http.request(
    {
      url: '/detectRecord/exportIntrusionCaptureRecord',
      method: 'post',
      responseType: 'blob',
      data,
    },
    {
      isTransformResponse: false,
    },
  );
};

/**
 * @description: 保密要害部位--监测记录--导出门禁记录
 */
export const exportAccessRecord = (data: QueryAccessRecordParams) => {
  return http.request(
    {
      url: '/detectRecord/exportAccessControlRecord',
      method: 'post',
      responseType: 'blob',
      data,
    },
    {
      isTransformResponse: false,
    },
  );
};

/**
 * @description: 保密要害部位--总览--查询今日出入抓拍记录数
 */
export const getTodayCaptureRecordCount = () => {
  return http.request({
    url: '/detectRecord/queryTodayIntrusionCaptureCount',
    method: 'get',
  });
};

/**
 * @description: 保密要害部位--总览--查询近几日出入抓拍统计
 */
export interface GetRecentDaysCaptureRecordCountRes {
  date: string; // 日期yyyy-MM-dd
  count: number; // 入侵抓拍数量
}
export const getRecentDaysCaptureRecordCount = (day: number) => {
  return http.request<GetRecentDaysCaptureRecordCountRes[]>({
    url: `/detectRecord/queryRecentIntrusionCaptureStatistic?day=${day}`,
    method: 'get',
  });
};

/**
 * @description: 院区监控区域管理--查询院区监控区域列表
 */
export const getSurveillanceAreaList = (data: GetPositionListParams) => {
  return http.request({
    url: '/cameraGroup/queryHospitalKeyAreas',
    method: 'post',
    data,
  });
};
