import axios from 'axios';

const API = axios.create({
  baseURL: '/api',
  withCredentials: true,
  headers: { 'Content-Type': 'application/json' },
});

// Auth
export const login = (data) => API.post('/auth/login', data);
export const logout = () => API.post('/auth/logout');
export const register = (data) => API.post('/auth/register', data);
export const getMe = () => API.get('/auth/me');

// Products
export const getProducts = () => API.get('/products');
export const getProduct = (id) => API.get(`/products/${id}`);
export const createProduct = (data) => API.post('/products', data);
export const updateProduct = (id, data) => API.put(`/products/${id}`, data);
export const deleteProduct = (id) => API.delete(`/products/${id}`);

// Sales
export const getSales = () => API.get('/sales');
export const getSale = (id) => API.get(`/sales/${id}`);
export const createSale = (data) => API.post('/sales', data);
export const updateSale = (id, data) => API.put(`/sales/${id}`, data);
export const deleteSale = (id) => API.delete(`/sales/${id}`);

// Stock
export const getStocks = () => API.get('/stock');
export const updateStock = (id, data) => API.put(`/stock/${id}`, data);
export const deleteStock = (id) => API.delete(`/stock/${id}`);

// Reports
export const getDailySalesReport = (date) =>
  API.get('/reports/daily-sales', { params: { date } });
export const getDailyStockReport = () => API.get('/reports/daily-stock');

export default API;
