import { requestClient } from '#/api/request';

const prefix = 'online-consultation/';

/**
 * 获取默认医生ID
 */
export async function getDefaultDoctorId() {
  return requestClient.get<any>(`${prefix}get-default-doctor-id`);
}

/**
 * 创建或获取聊天房间
 * @param data
 */
export async function getOrCreateChatRoom(data: any) {
  return requestClient.post<any>(`${prefix}get-or-create-chat-room`, data);
}

/**
 * 结束在线复诊
 * @param data
 */
export async function endConsultation(data: any) {
  return requestClient.post<any>(`${prefix}end-consultation`, data);
}

/**
 * 获取快速回复模板列表
 * @param data
 */
export async function getQuickReplyList(data: any) {
  return requestClient.get<any>(`${prefix}get-quick-reply-list`, { params: data });
}

/**
 * 创建快速回复模板
 * @param data
 */
export async function createQuickReply(data: any) {
  return requestClient.post<any>(`${prefix}create-quick-reply`, data);
}

/**
 * 更新快速回复模板
 * @param data
 */
export async function updateQuickReply(data: any) {
  return requestClient.post<any>(`${prefix}update-quick-reply`, data);
}

/**
 * 删除快速回复模板
 * @param data
 */
export async function deleteQuickReply(data: any) {
  return requestClient.post<any>(`${prefix}delete-quick-reply`, data);
}

/**
 * 获取在线复诊患者列表
 * @param type 类型：1=当前（待接诊），2=历史（已接诊）
 */
export async function getPatientList(type: number) {
  return requestClient.get<any>(`${prefix}get-patient-list`, { params: { type } });
}

/**
 * 获取患者详情
 * @param roomId 房间ID（可选，如果没有room_id但有registerId，可以通过registerId查询）
 * @param registerId 挂号ID（可选）
 */
export async function getPatientDetail(roomId?: string, registerId?: number) {
  const params: any = {};
  if (roomId) {
    params.room_id = roomId;
  }
  if (registerId) {
    params.register_id = registerId;
  }
  return requestClient.get<any>(`${prefix}get-patient-detail`, { params });
}

/**
 * 接诊
 * @param registerId 挂号ID
 */
export async function reception(registerId: number) {
  return requestClient.post<any>(`${prefix}reception`, { 
    register_id: registerId
  });
}

/**
 * 获取挂号诊所信息
 * @param registerId 挂号ID
 */
export async function getRegisterStoreInfo(registerId: number) {
  return requestClient.get<any>(`${prefix}get-register-store-info`, { 
    params: { register_id: registerId }
  });
}

/**
 * 根据挂号ID获取药品信息
 * @param registerId 挂号ID
 * @param storeId 门店ID
 */
export async function getDrugsByRegisterId(registerId: number, storeId: number) {
  return requestClient.get<any>(`${prefix}get-drugs-by-register-id`, { 
    params: { register_id: registerId, store_id: storeId }
  });
}

/**
 * 获取患者订单列表
 * @param registerId 挂号ID
 */
export async function getPatientOrders(registerId: number) {
  return requestClient.get<any>(`${prefix}get-patient-orders`, { 
    params: { register_id: registerId }
  });
}

/**
 * 调整订单商品价格
 * @param data 调整参数
 */
export async function adjustOrderItemPrice(data: {
  product_order_id: number;
  product_order_item_id: number;
  new_price: number;
  register_id: number;
  remark?: string;
}) {
  return requestClient.post<any>(`${prefix}adjust-order-item-price`, data);
}