import { defineStore } from "pinia"; import { ref, computed } from "vue"; import FinancialStatisticsService from "@/services/financialStatistics"; import type { FinancialStatistics } from "@/services/financialStatistics"; export const useFinancialStatisticsStore = defineStore( "financialStatistics", () => { const statistics = ref(null); const loading = ref(false); const error = ref(null); const isLoading = computed(() => loading.value); const hasError = computed(() => error.value !== null); const getError = computed(() => error.value); const hasData = computed(() => statistics.value !== null); async function fetchStatistics(): Promise { loading.value = true; error.value = null; try { statistics.value = await FinancialStatisticsService.getStatistics(); } catch (err: unknown) { error.value = err instanceof Error ? err.message : "Erreur lors du chargement des statistiques financières."; } finally { loading.value = false; } } function clearStatistics(): void { statistics.value = null; error.value = null; } return { statistics, loading, error, isLoading, hasError, getError, hasData, fetchStatistics, clearStatistics, }; } );