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

/**
 * @description: 获取用户访问记录接口参数
 */
export interface UserAccessRecordQueryParams {
  /** 页码 */
  pageNumber: number;
  /** 页面大小 */
  pageSize: number;
  /** 查询员工姓名 */
  nickname?: string;
  /** 查询工号 */
  stuffNo?: string;
  /** 查询部门ID */
  deptId?: string;
  /** 设置排序字段 */
  sortKey?: string;
  /** 设置排序方式 */
  sortType?: string;
}

/**
 * @description: 用户访问记录列表数据
 */
export interface UserAccessRecord {
  /** 系统分配id */
  userId: number;
  /** 登录账户名 */
  username: string;
  /** 工号 */
  stuffNo: string;
  /** 姓名 */
  nickname: string;
  deptId: number;
  deptName: string;
  statisticDay: number;
  statisticMonth: number;
  statisticAll: number;
}

/**
 * @description: 用户访问记录数据
 */
export interface UserAccessRecordList {
  list: UserAccessRecord[];
  pageNumber: number;
  pageSize: number;
  total: number;
}

/**
 * @description: 获取用户访问记录
 */
export const getUserAccessRecords = (params: UserAccessRecordQueryParams) => {
  return http.request<UserAccessRecordList>({
    url: '/userRecord/getList',
    method: 'get',
    params,
  });
};

/**
 * @description: 绘图时间段&员工&车间查询参数
 */
export interface ChartQuery {
  /** 开始时间 */
  startTime?: string;
  /** 结束时间 */
  endTime?: string;
  /** 员工id */
  userId?: string;
  /** 车间id */
  workshopList?: number[];
}

/**
 * @description: 车间被访问次数数据
 */
export interface WorkshopVisitedTimes {
  workshopId: number;
  workshopName: string;
  count: number;
}

/**
 * @description: 获取车间被访问次数数据
 */
export const getWorkshopVisitedTimes = (params: ChartQuery) => {
  return http.request<WorkshopVisitedTimes[]>({
    url: '/userRecord/statisticByWorkshop',
    method: 'get',
    params,
  });
};

/**
 * @description: 相机被访问次数数据
 */
export interface CameraVisitedTimes {
  cameraCode: string;
  cameraName: string;
  count: number;
}

export interface CameraVisitedTimeItem {
  workshopId: number;
  workshopCode: string;
  workshopName: string;
  cameraCounts: CameraVisitedTimes[];
}

/**
 * @description: 获取相机被访问次数数据
 */
export const getCameraVisitedTimes = (body: ChartQuery) => {
  return http.request<CameraVisitedTimeItem[]>({
    url: '/userRecord/statisticByCamera',
    method: 'post',
    data: body,
  });
};

/**
 * @description: 获取员工访问车间次数数据
 */
export const getUserVisitTimes = (params: ChartQuery) => {
  return http.request<WorkshopVisitedTimes[]>({
    url: '/userRecord/statisticByWorkshopPerUser',
    method: 'get',
    params,
  });
};

/**
 * @description: 员工日访问车间次数数据
 */
export interface UserDailyVisitTimes {
  time: string[];
  data: { counts: number; workshopId: number; workshopName: string }[];
}

/**
 * @description: 获取员工日访问车间次数数据
 */
export const getUserDailyVisitTimes = (body: ChartQuery) => {
  return http.request<UserDailyVisitTimes>({
    url: '/userRecord/statisticByWorkshopPerDay',
    method: 'post',
    data: body,
  });
};
