import { bluebookAiAgent } from "@/xiaolanbenlib/api/index";
import request from "@/xiaolanbenlib/module/axios.js";

import {
  TVisitorAgent,
  TVisitorMessage,
  TVisitorChat,
  TSessionItem,
} from "@/types/visitor";

// 编辑差评记录的答案消息--编辑后则自动标识为已处理
export const editVisitorDislikeAnswer = (data: {
  agentId: string,
  answer: string ,
  links: string[],
  msgId: string,
  pics: string[],
  questions : string[],
  visitorId: string
}) => {
  return request.put(
    `${bluebookAiAgent}api/v1/my/visitor/message/answer`,
    data
  );
};

// 删除指定的差评待处理记录
export const deleteVisitorDislikeAnswer = (data: {
  visitorId: string|number;
  msgId: string|number;
}) => {
  return request.delete(`${bluebookAiAgent}api/v1/my/visitor/dislike/message`, {
    params: data,
  });
};

// 获取未处理的差评记录列表
export type TVisitorDislikeMessagesResponse = {
  data: [TVisitorChat[]];
  nextId: string;
  totalCount: number;
};

export const getVisitorDislikeMessages = (data: {
  agentId: string;
  startId: string;
  pageSize: number;
}) => {
  return request.get<TVisitorDislikeMessagesResponse>(
    `${bluebookAiAgent}api/v1/my/visitor/dislike/messages`,
    { params: data }
  );
};

// 访客访问详情--访客信息
export type TVisotorInfoResponse = {
  agentId: string;
  agentStatus: string;
  avatarUrl: string;
  chatRound: number;
  dislikeCnt: number;
  isEnt: false;
  lastChatTime: "2025-05-21T07:09:45.814Z";
  myAgentId: string;
  myAgentName: string;
  name: string;
  position: string;
  visitTimes: number;
  visitorId: number;
};
export const getVisitorInfo = (visitorId: number | string) => {
  return request.get<TVisitorAgent>(
    `${bluebookAiAgent}api/v1/my/visitor/info`,
    { params: { visitorId } }
  );
};

// 获取好评记录列表--包含已读未读
export type TVisitorLikeMessagesResponse = {
  data: TVisitorMessage[];
  nextId: string;
  totalCount: number;
};
export const getVisitorLikeMessages = (data: {
  visitorId: string;
  startId: string;
  pageSize: number;
}) => {
  return request.get<TVisitorLikeMessagesResponse>(
    `${bluebookAiAgent}api/v1/my/visitor/like/messages`,
    { params: data }
  );
};

// 访客数据列表--列表会按我的智能体明细展示
export type TVisitorListResponse = {
  data: [];
  nextId: string;
  totalCount: number;
};
export const getVisitorList = (data: {
  agentId: string;
  startId: string;
  pageSize: string;
}) => {
  return request.get<TVisitorListResponse>(
    `${bluebookAiAgent}api/v1/my/visitor/list`,
    { params: data }
  );
};

// 访客访问详情--访客聊天记录
export type TVisitorMessagesResponse = {
  data: TVisitorChat[];
  nextId: string;
  totalCount: number;
};
export const getVisitorMessages = (data: {
  visitorId: string | number;
  startId?: string;
  sessionId: string;
  pageSize: number;
}) => {
  return request.get<TVisitorMessagesResponse>(
    `${bluebookAiAgent}api/v1/my/visitor/session/messages`,
    { params: data }
  );
};

// 访客访问详情--获取访问的会话列表, 仅在 startId 为空时返回 totalCount

export const getVisitorSessions = (data: {
  visitorId: string | number;
  startId: string;
  pageSize: number;
}) => {
  return request.get<{
    data: TSessionItem[];
    nextId: string;
    totalCount: number;
  }>(`${bluebookAiAgent}api/v1/my/visitor/sessions`, { params: data });
};

// 访客聊天记录 获取指定 msgId 前后各N条；用于查看好差评记录的访客详情
export const getVisitorMessagesByMsgId = (data: {
  visitorId: string;
  msgId: string;
  size: number;
}) => {
  return request.get<TVisitorChat[]>(
    `${bluebookAiAgent}api/v1/my/visitor/messages/byMsgId`,
    { params: data }
  );
};

// 访问数据汇总
export type TVisitorSummary = {
  sumChatUv?: number; // 总聊天UV ,
  sumPv?: number; // 总PV ,
  sumUv?: number; // 总UV ,
  todayChatUv?: number; // 今日聊天UV ,
  todayPv?: number; // 今日PV ,
  todayUv?: number; // 今日UV ,
  unprocessedDislikeCnt?: number; // 未处理差评记录数 ,
  unreadLikeCnt?: number; // 未查看点赞记录数
};
export const getVisitorSummary = (agentId?: string) => {
  return request.get<TVisitorSummary>(
    `${bluebookAiAgent}api/v1/my/visitor/summary`,
    { params: { agentId } }
  );
};
