import { defineStore } from 'pinia'
import { ref } from 'vue'
import { useApi } from '../composables/useApi.js'

export const useDbMaintenanceStore = defineStore('dbMaintenance', () => {
  const api = useApi()
  const tables = ref([])
  const loading = ref(false)

  async function loadStats() {
    loading.value = true
    try {
      const body = await api.get('/api/admin/maintenance/db-stats')
      tables.value = body.tables || []
    } finally {
      loading.value = false
    }
  }

  async function runVacuum() {
    return await api.post('/api/admin/maintenance/vacuum')
  }

  return { tables, loading, loadStats, runVacuum }
})
