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

export namespace ChatflowApi {
  export interface ChatParams {
    appid: string;
  }

  export interface CompletionsBody {
    userId: string;
    conversationId: string;
    content: string;
    inputs: {
      [key: string]: any;
    };
    files: [];
  }

  export interface ChatListBody {
    userId: string;
    lastId: string;
    sortBy: string;
    limit: string;
    content?: string | undefined;
  }

  export interface ChatListResult {
    id: string;
    name: string;
    inputs: {
      [key: string]: any;
    };
    status: string;
    introduction: string;
    createAt: string;
    updatedAt: string;
  }
}

// 聊天流
export async function sendChatflow(
  params: ChatflowApi.ChatParams,
  data: ChatflowApi.CompletionsBody,
) {
  return requestClient.post(`/v1/chat/completions/${params.appid}`, data);
}

export async function getChatList(
  params: ChatflowApi.ChatParams,
  data: ChatflowApi.ChatListBody,
) {
  const url = params.appid
    ? `/v1/chat/conversations/${params.appid}`
    : '/v1/chat/conversations/';
  return requestClient.request<ChatflowApi.ChatListResult[]>(url, {
    data,
    method: 'POST',
  });
}

// export function stopChatflow(data){
//   return requestClient.post('/v1/chat/stopMessagesStream', data);
// };
//
// export function getChatflowList(data){
//   return requestClient.post('/v1/chat/messages', data);
// };
//
// export function deleteChatflow(data){
//   return requestClient.delete('/v1/chat/messages/suggested', data);
// };
