import { useAuth } from '@/context/auth';
import { useActorRole } from '@/hooks';
import { MOCK_VIEWER_USER_ID } from '../constants';
import type { TicketAuthorRole } from '../types';

/**
 * The current viewer's `{ userId, role }` for the tickets domain. `userId` drives `isMine` (whose bubble is
 * whose); `role` labels an optimistic bubble's author. On the real path the authenticated `/me` id wins;
 * under mock auth (no id yet) it falls back to the per-role mock "me" so bubbles still mirror correctly in
 * whichever app is open (customer vs nurse). Not exported from the barrel — an internal helper the domain
 * hooks share.
 */
export function useTicketViewer(): { userId: number; role: TicketAuthorRole } {
  const [auth] = useAuth();
  const role = useActorRole();
  const userId = auth.currentUser?.id ?? MOCK_VIEWER_USER_ID[role] ?? MOCK_VIEWER_USER_ID.customer;
  return { userId, role };
}
