"use server";

import { serverFetchJson } from "@/app/utils/fetchUtil";
import { BASE_API_URL } from "@/config/api";
import { cache } from "react";

export interface TokenResponse {
    accessToken: string;
    refreshToken: string;
}

export interface TokenRequest {
    refreshToken: string;
}

export const fetchTokenDetails = cache(async (data: TokenRequest) => {
    return serverFetchJson<TokenResponse>(`${BASE_API_URL}/refresh-token`, 
    {
        method: "POST",
        body: JSON.stringify(data),
        headers: { "Content-Type": "application/json" },
      },
    );
});