import { create } from 'zustand'
import api from '../api/axios'

export const useReportStore = create((set) => ({
  daily: null,
  weekly: null,
  monthly: null,
  loading: false,
  error: null,

  fetchDailyReport: async () => {
    set({ loading: true, error: null })
    try {
      const res = await api.get('/reports/daily')
      set({ daily: res.data, loading: false })
      return res.data
    } catch (err) {
      set({ loading: false, error: err.message })
      throw err
    }
  },

  fetchWeeklyReport: async () => {
    set({ loading: true, error: null })
    try {
      const res = await api.get('/reports/weekly')
      set({ weekly: res.data, loading: false })
      return res.data
    } catch (err) {
      set({ loading: false, error: err.message })
      throw err
    }
  },

  fetchMonthlyReport: async () => {
    set({ loading: true, error: null })
    try {
      const res = await api.get('/reports/monthly')
      set({ monthly: res.data, loading: false })
      return res.data
    } catch (err) {
      set({ loading: false, error: err.message })
      throw err
    }
  }
}))

