'use client'

import { useQuery } from '@tanstack/react-query'
import { apiClient } from '../client'
import type { ApiMailAccountDetail } from '../types'
import { useAuthReady } from '../use-auth-ready'

export function useMailAccount(accountId: string | null) {
  const { ready, authenticated } = useAuthReady()

  return useQuery({
    queryKey: ['mail-account', accountId],
    enabled: ready && authenticated && Boolean(accountId),
    queryFn: () => apiClient.get<ApiMailAccountDetail>(`/mail/accounts/${accountId}`),
  })
}
