'use client'

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

export function useMailOAuthProviders() {
  const { ready, authenticated } = useAuthReady()

  return useQuery({
    queryKey: ['mail-oauth-providers'],
    queryFn: () =>
      apiClient.get<MailOAuthProvidersResponse>('/mail/accounts/oauth/providers'),
    enabled: ready && authenticated,
    staleTime: 60_000,
  })
}
