const API_URL = 'http://localhost:8080';


export async function loginUser(Email:string, Password: string) {
    const res = await fetch(`${API_URL}/login`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ Email, Password }),
  });
  return res;
}

export async function registerUser(request: { Email: string; Username: string; Password: string; }){
  console.log(request);
  const res = await fetch(`${API_URL}/register`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(request),
  });
  
  return res; 
}
    
export async function fetchUserProfile(token: string) {
  const res = await fetch(`${API_URL}/profile`, {
    headers: { 'Authorization': `Bearer ${token}` },
  });
  if (!res.ok) throw new Error('Profil konnte nicht geladen werden');
  return res.json(); // { id: number, email: string, name: string }
}