import fetch from 'node-fetch';

export async function tessApiRequest(method: string, endpoint: string, body: any = {}, token: string): Promise<any> {
  const response = await fetch(`https://api.tess.pareto.io${endpoint}`, {
    method,
    headers: {
      Authorization: `Bearer ${token}`,
      'Content-Type': 'application/json'
    },
    body: method === 'GET' ? undefined : JSON.stringify(body)
  });

  if (!response.ok) {
    throw new Error(`Tess API error: ${response.statusText}`);
  }

  return response.json();
}
