/* |-------------------------------------------------------------------------- | Agência PSI |-------------------------------------------------------------------------- | Arquivo: src/features/agenda/services/_tenantGuards.js | | Guards compartilhados entre composables e repositories do feature agenda. | Antes: assertTenantId e getUid duplicados em 3+ arquivos. |-------------------------------------------------------------------------- */ import { supabase } from '@/lib/supabase/client'; export function assertTenantId(tenantId) { if (!tenantId || tenantId === 'null' || tenantId === 'undefined') { throw new Error('Tenant ativo inválido. Selecione a clínica/tenant antes de operar na agenda.'); } } export async function getUid() { const { data, error } = await supabase.auth.getUser(); if (error) throw error; const uid = data?.user?.id; if (!uid) throw new Error('Usuário não autenticado.'); return uid; } export function assertIsoRange(startISO, endISO) { if (!startISO || !endISO) throw new Error('Intervalo inválido (startISO/endISO).'); } export function sanitizeOwnerIds(ownerIds) { return (ownerIds || []).filter((id) => typeof id === 'string' && id && id !== 'null' && id !== 'undefined'); }