'use server';

import { fetchJson } from '@/lib/utils/server';
import { ResultDto } from '@/types/response/common';
import {
	FeedPostDetail,
	FeedRepliesResponse,
	FeedSuggestedFollowsResponse
} from '@/types/feed/post';

export async function fetchFeedPost(postID: number): Promise<ResultDto<FeedPostDetail>> {
	return await fetchJson<FeedPostDetail>(`/api/feed/post/${postID}`, {
		method: 'GET',
		headers: { 'Accept': 'application/json' }
	});
}

export async function fetchFeedReplies(postID: number, page = 1, perPage = 30): Promise<ResultDto<FeedRepliesResponse>> {
	return await fetchJson<FeedRepliesResponse>(`/api/feed/post/${postID}/replies?page=${page}&perPage=${perPage}`, {
		method: 'GET',
		headers: { 'Accept': 'application/json' }
	});
}

export async function fetchSuggestedFollows(top = 5): Promise<ResultDto<FeedSuggestedFollowsResponse>> {
	return await fetchJson<FeedSuggestedFollowsResponse>(`/api/feed/suggested-follows?top=${top}`, {
		method: 'GET',
		headers: { 'Accept': 'application/json' }
	});
}