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

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

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

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

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

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

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