'use server';

import { cookies } from 'next/headers';
import { LoginLogRequest  } from '@/types/request/account';
import { MemberResponse } from '@/types/response/account/member';
import { ResultDto } from '@/types/response/common';
import { fetchJson } from '@/lib/utils/server';

// 회원정보 조회
export async function fetchMemberInfo(): Promise<ResultDto<MemberResponse>> {
	const res = await fetchJson<MemberResponse>('/api/auth/profile', {
		method: 'GET'
	});

	if (res.success) {
		(await cookies()).set('member', JSON.stringify(res.data));
	}

    return res;
}

// 로그인 기록
export async function fetchLoginLog({Page = 1, Type = 'today', PerPage = 20} : LoginLogRequest) {
	return await fetchJson(`/api/mypage/login-logs?page=${Page}&type=${Type}&perPage=${PerPage}`, {
		method: 'GET',
		headers: {
			'Accept': 'application/json'
		}
	});
}