import type { List } from '@/model';
import request from '@/request/alova';
import type { ConsultantPeopleModel, ChatMessageModel } from '@/model/consult.model';

// 获取当前用户所在组织下的咨询人列表
export function getConsultantListMethod(name?: string) {
  return request.Post<List<ConsultantPeopleModel>>(
    '/fdhb-pc/consultManage/getConsultPats',
    {},
    {
      hitSource: /consult$/, // 匹配失效源
      params: { name },
    }
  );
}
// 获取某个咨询记录下的所有消息
export function getAllConsultChatListMethod(id: number) {
  return request.Post<List<ConsultantPeopleModel>>(`/fdhb-pc/consultManage/getAllMsgs/${id}`);
}
// 发送咨询信息
export function sendConsultChatMethod(patientId: number, query?: Record<string, any>) {
  return request.Post<void>(
    `/fdhb-pc/consultManage/sendConsultMsg/${patientId}`,
    {
      consultRecordId: query?.consultRecordId,
      messageType: query?.messageType,
      messageContent: query?.messageContent,
    },
    {
      hitSource: /consultChat$/, // 匹配失效源
    }
  );
}
// 置顶患者
export function pinConsultantMethod(id: number) {
  return request.Post<void>(`/fdhb-pc/consultManage/top/${id}`);
}
// 取消置顶
export function cancelPinConsultantMethod(id: number) {
  return request.Post<void>(`/fdhb-pc/consultManage/topCancel/${id}`);
} 
// 获取患者聊天分页列表
export function getConsultRecordListMethod(page: number, size: number, patientId: string) {
  return request.Post<List<ChatMessageModel>>(
    `/fdhb-pc/consultManage/pageConsult/${patientId}`,
    {},
    {
      params: { pageNum: page, pageSize: size },
    }
  );
}
// 获取搜索患者聊天记录分页列表
export function getConsultChatListMethod(page: number, size: number, patientId: string, query?: Record<string, any>) {
  return request.Get<List<ChatMessageModel>>(`/fdhb-pc/consultManage/pageConsultMsg/${patientId}`, {
    hitSource: /consultChat$/, // 匹配失效源
    params: {
      keyWord: query?.keyWord,
      pageNum: page,
      pageSize: size,
    },
  });
}
// 刷新当前聊天框
export function refreshConsultMethod(id: string) {
  return request.Post<void>(`/fdhb-pc/consultManage/getLatestMsgs/${id}`, {
    hitSource: /consultRefresh$/, // 匹配失效源
  });
}
