import { useLiveQuery } from 'dexie-react-hooks';
import { charactersRepo } from '@/lib/db/repositories';
import type { Character } from '@/lib/schemas';

export function useCharacters(campaignId: string): Character[] {
  return useLiveQuery(() => charactersRepo.listByCampaign(campaignId), [campaignId], []);
}

/** All player characters across every campaign — PCs are campaign-agnostic. */
export function useAllPcs(): Character[] {
  return useLiveQuery(() => charactersRepo.listAllPcs(), [], []);
}

export function useCharacter(id: string): Character | undefined {
  return useLiveQuery(() => charactersRepo.get(id), [id], undefined);
}
