import axios from 'axios';
import { API_BASE_URL } from '../utils/constants';

const drohnenfuehrerApi = axios.create({
  baseURL: `${API_BASE_URL}/api/drohnenfuehrer`,
  timeout: 10000,
  headers: { 'Content-Type': 'application/json' }
});

drohnenfuehrerApi.interceptors.request.use((config) => {
  const token = localStorage.getItem('drohnenfuehrerToken');
  if (token) config.headers.Authorization = `Bearer ${token}`;
  return config;
});

export const drohnenfuehrerLogin = async (email, password) => {
  const response = await drohnenfuehrerApi.post('/login', { email, password });
  return response.data;
};

export const setDrohnenfuehrerPassword = async (email, newPassword) => {
  const response = await drohnenfuehrerApi.post('/set-password', { email, newPassword });
  return response.data;
};

export const getDrohnenfuehrerMe = async () => {
  const response = await drohnenfuehrerApi.get('/me');
  return response.data;
};

export const updateDrohnenfuehrerMe = async (data) => {
  const response = await drohnenfuehrerApi.put('/me', data);
  return response.data;
};
