import { useQuery } from '@tanstack/react-query';
import { UserProfileSchema, type UserProfile } from '@sar/api-interface';
import { apiFetch } from '../api-client';

export const AUTH_KEYS = {
  me: ['auth', 'me'] as const,
};

export function useCurrentUser() {
  return useQuery<UserProfile, Error>({
    queryKey: AUTH_KEYS.me,
    queryFn: async () => {
      const res = await apiFetch('/auth/me');
      return UserProfileSchema.parse(res);
    },
    staleTime: 5 * 60 * 1000,
  });
}
