import { defineStore } from 'pinia'
import { ref } from 'vue'
import api from '@/services/api'

export const useExpenseStore = defineStore('expense', () => {
  const isLoading = ref(false)
  const error = ref(null)

  async function createExpense(expenseData) {
    isLoading.value = true
    error.value = null
    try {
      const response = await api.post('/api/v1/expenses/', expenseData)
      return response.data
    } catch (err) {
      error.value = err.response?.data?.detail || err.message
      throw err
    } finally {
      isLoading.value = false
    }
  }

  return {
    isLoading,
    error,
    createExpense,
  }
})