import { Res } from '#interfaces/IApi';
import { TokenService } from '#services/auth/tokenService';

/**
 * Clear both auth cookies (access_token + refresh_token) with the same options
 * used when they were set, ensuring proper cookie deletion across environments.
 */
export function clearAuthCookies(res: Res): void {
	const accessOptions = TokenService.getAccessTokenCookieOptions();
	res.clearCookie('access_token', {
		httpOnly: accessOptions.httpOnly,
		secure: accessOptions.secure,
		sameSite: accessOptions.sameSite,
		path: accessOptions.path,
		...(accessOptions.domain ? { domain: accessOptions.domain } : {}),
	});

	const refreshOptions = TokenService.getRefreshTokenCookieOptions();
	res.clearCookie('refresh_token', {
		httpOnly: refreshOptions.httpOnly,
		secure: refreshOptions.secure,
		sameSite: refreshOptions.sameSite,
		path: refreshOptions.path,
		...(refreshOptions.domain ? { domain: refreshOptions.domain } : {}),
	});
}
