import { request } from '@umijs/max';
import type { CurrentUser, FriendUser, HistoryMessage, ListItemDataType, MessageItem, UserInfo } from './data.d';
import { CommonResponse } from '@/types/common';

export async function queryCurrent(): Promise<{ data: CurrentUser }> {
  return request('/user-api/info');
}
export async function searchUsername(params: {username: string}) : Promise<{data: UserInfo[]}> {
  return request('/user-api/search', {
    params: params,
    method: "GET"
  })
}

export async function addFriend(userId: string) : Promise<CommonResponse<String>> {
  return request('/user-api/friend/request', {
    data: {
      friendId: userId,
    },
    method: "POST"
  })
}
export async function queryFriendList(): Promise<CommonResponse<FriendUser[]>> {
  return request('/user-api/friend/list');
}

export async function acceptFriendRequest(friendId: string): Promise<CommonResponse<string>> {
  return request('/user-api/friend/accept', {
    method: 'POST',
    data: { friendId },
  });
}

export async function rejectFriendRequest(friendId: string): Promise<CommonResponse<string>> {
  return request('/user-api/friend/reject', {
    method: 'POST',
    data: { friendId },
  });
}
export async function queryHistoryMessages(): Promise<CommonResponse<HistoryMessage[]>> {
  return request('/user-api/message/history/friend', {
    method: 'GET',
  });
}
export async function queryFriendDynamic(): Promise<CommonResponse<HistoryMessage[]>> {
  return request('/story/activity/authorized-items', {
    method: 'GET',
  });
}
export async function queryFakeList(params: {
  count: number;
}): Promise<{ data: { list: ListItemDataType[] } }> {
  return request('/api/fake_list_Detail', {
    params,
  });
}
