import api from './client'

export const habitsApi = {
  list: () => api.get('/habits').then(r => r.data),
  get: (id) => api.get(`/habits/${id}`).then(r => r.data),
  create: (data) => api.post('/habits', data).then(r => r.data),
  update: (id, data) => api.put(`/habits/${id}`, data).then(r => r.data),
  delete: (id) => api.delete(`/habits/${id}`),
  
  log: (id, data = {}) => api.post(`/habits/${id}/log`, data).then(r => r.data),
  getLogs: (id, days = 30) => api.get(`/habits/${id}/logs?days=${days}`).then(r => r.data),
  deleteLog: (habitId, logId) => api.delete(`/habits/${habitId}/logs/${logId}`),
  
  getStats: () => api.get('/habits/stats').then(r => r.data),
  getHabitStats: (id) => api.get(`/habits/${id}/stats`).then(r => r.data),

  // Freezes
  getFreezes: (habitId) => api.get(`/habits/${habitId}/freezes`).then(r => r.data),
  addFreeze: (habitId, data) => api.post(`/habits/${habitId}/freezes`, data).then(r => r.data),
  deleteFreeze: (habitId, freezeId) => api.delete(`/habits/${habitId}/freezes/${freezeId}`),
}
