import { LocalDnsProvider } from './local';
import { Rfc2136DnsProvider } from './rfc2136';
import { resolveDnsProviderName, type DnsProvider } from './types';

let cachedProvider: DnsProvider | undefined;

export function createDnsProvider(): DnsProvider {
  if (cachedProvider) {
    return cachedProvider;
  }

  cachedProvider =
    resolveDnsProviderName() === 'rfc2136'
      ? new Rfc2136DnsProvider()
      : new LocalDnsProvider();

  return cachedProvider;
}

export function resetDnsProviderCache(): void {
  cachedProvider = undefined;
}

export type { DnsProvider, DnsProviderName, DnsRecordSpec } from './types';
export { resolveDnsProviderName } from './types';
