/* |-------------------------------------------------------------------------- | Agência PSI |-------------------------------------------------------------------------- | Criado e desenvolvido por Leonardo Nohama | | Tecnologia aplicada à escuta. | Estrutura para o cuidado. | | Arquivo: src/stores/saasHealthStore.js | Data: 2026 | Local: São Carlos/SP — Brasil |-------------------------------------------------------------------------- | © 2026 — Todos os direitos reservados |-------------------------------------------------------------------------- */ import { defineStore } from 'pinia'; import { supabase } from '@/lib/supabase/client'; export const useSaasHealthStore = defineStore('saasHealth', { state: () => ({ mismatchCount: 0, loading: false, lastLoadedAt: null }), actions: { async loadMismatchCount({ force = false } = {}) { if (this.loading) return; if (!force && this.lastLoadedAt && Date.now() - this.lastLoadedAt < 30_000) return; // cache 30s this.loading = true; try { const { count, error } = await supabase.from('v_subscription_feature_mismatch').select('*', { count: 'exact', head: true }); if (error) throw error; this.mismatchCount = Number(count || 0); this.lastLoadedAt = Date.now(); } finally { this.loading = false; } } } });