'use server';

import { ResultDto } from '@/types/response/common';
import { ChatRoomHistory } from '@/types/chat';
import { fetchJson } from '@/lib/utils/server';

// 룸 최근 메시지 히스토리 조회 (익명 허용 — /chat SSR 초기 로드용)
export async function fetchChatRoomHistory(roomKey: string, count: number = 50): Promise<ResultDto<ChatRoomHistory>>
{
	return await fetchJson<ChatRoomHistory>(`/api/chat/rooms/${encodeURIComponent(roomKey)}/messages?count=${count}`, {
		method: 'GET',
		headers: {
			'Accept': 'application/json'
		}
	});
}