/**
 * Client-only session token persistence. The single place that writes/clears the auth
 * cookies via the cookie manager — shared by the `services/auth` hooks and the fetch
 * layer's silent-refresh path so token storage never diverges.
 *
 * Import from client components / hooks / the client fetch layer only (uses the client
 * cookie manager, which needs `window`). Never from an RSC.
 */
import { AUTH_ACCESS_COOKIE_OPTIONS, AUTH_REFRESH_COOKIE_OPTIONS, COOKIE_NAMES } from '@/lib/cookies';
import { deleteClientCookie, setClientCookie } from '@/lib/cookies/client';

interface TokenPair {
  accessToken: string;
  refreshToken: string;
}

export function persistAuthTokens(tokens: TokenPair): void {
  setClientCookie(COOKIE_NAMES.ACCESS_TOKEN, tokens.accessToken, AUTH_ACCESS_COOKIE_OPTIONS);
  setClientCookie(COOKIE_NAMES.REFRESH_TOKEN, tokens.refreshToken, AUTH_REFRESH_COOKIE_OPTIONS);
}

export function clearAuthTokens(): void {
  deleteClientCookie(COOKIE_NAMES.ACCESS_TOKEN);
  deleteClientCookie(COOKIE_NAMES.REFRESH_TOKEN);
}
