'use server';

import { fetchJson } from '@/lib/utils/server';
import { ResultDto } from '@/types/response/common';
import {
	FeedTimelineResponse,
	FeedTagPageResponse
} from '@/types/feed/card';

export async function fetchTimeline(page = 1, perPage = 20): Promise<ResultDto<FeedTimelineResponse>> {
	return await fetchJson<FeedTimelineResponse>(`/api/feed/timeline?page=${page}&perPage=${perPage}`, {
		method: 'GET',
		headers: { 'Accept': 'application/json' }
	});
}

export async function fetchForYou(page = 1, perPage = 20): Promise<ResultDto<FeedTimelineResponse>> {
	return await fetchJson<FeedTimelineResponse>(`/api/feed/foryou?page=${page}&perPage=${perPage}`, {
		method: 'GET',
		headers: { 'Accept': 'application/json' }
	});
}

export async function fetchAll(page = 1, perPage = 20): Promise<ResultDto<FeedTimelineResponse>> {
	return await fetchJson<FeedTimelineResponse>(`/api/feed/all?page=${page}&perPage=${perPage}`, {
		method: 'GET',
		headers: { 'Accept': 'application/json' }
	});
}

export async function fetchByTag(slug: string, page = 1, perPage = 20): Promise<ResultDto<FeedTagPageResponse>> {
	return await fetchJson<FeedTagPageResponse>(`/api/feed/tag/${encodeURIComponent(slug)}?page=${page}&perPage=${perPage}`, {
		method: 'GET',
		headers: { 'Accept': 'application/json' }
	});
}

