import client from './client'

export const financeApi = {
  // Categories
  listCategories: async () => {
    const res = await client.get('finance/categories')
    return res.data
  },
  createCategory: async (data) => {
    const res = await client.post('finance/categories', data)
    return res.data
  },
  updateCategory: async (id, data) => {
    const res = await client.put(`finance/categories/${id}`, data)
    return res.data
  },
  deleteCategory: async (id) => {
    await client.delete(`finance/categories/${id}`)
  },

  // Transactions
  listTransactions: async (params = {}) => {
    const res = await client.get('finance/transactions', { params })
    return res.data
  },
  createTransaction: async (data) => {
    const res = await client.post('finance/transactions', data)
    return res.data
  },
  updateTransaction: async (id, data) => {
    const res = await client.put(`finance/transactions/${id}`, data)
    return res.data
  },
  deleteTransaction: async (id) => {
    await client.delete(`finance/transactions/${id}`)
  },

  // Summary & Analytics
  getSummary: async (params = {}) => {
    const res = await client.get('finance/summary', { params })
    return res.data
  },
  getAnalytics: async (params = {}) => {
    const res = await client.get('finance/analytics', { params })
    return res.data
  },
}
