import type { ProxyData, WhoIsOptions, WhoIsResponse } from './types';
import type { SocksClientOptions } from 'socks';
import { SocksClient } from 'socks';

export type { SocksClientOptions } from 'socks'
export declare function findWhoIsServer(tld: string): Promise<string>;
export declare function getWhoIsServer(tld: keyof typeof SERVERS): string | undefined;
export declare function getTLD(domain: string): keyof typeof SERVERS;
export declare function getParameters(server: string): string | undefined;
export declare class WhoIsParser {
  private static iterParse(rawData: string, outputData: any) {
    let lastStr = ''
    let lastField: string | null = null
    let lastLetter = ''

    for (let i = 0; i < rawData.length; i++) {
      const letter = rawData[i]
      if (letter === '\n' || (lastLetter === ':' && letter === ' ')) {
        if (lastStr.trim() in outputData) {
          lastField = lastStr.trim()
        }
        else if (lastField !== null) {
          const x = lastStr.trim()
          if (x !== '') {
            const obj = outputData[lastField]
            if (Array.isArray(obj))
              obj.push(x)
            else outputData[lastField] = x

            lastField = null
          }
        }
        lastStr = ''
      }
      else if (letter !== ':') {
        lastStr = lastStr + letter
      }
      lastLetter = letter as string
      if (lastStr === 'Record maintained by' || lastStr === '>>>')
        break
    }

    return outputData
  }

  public static parseData(rawData: string, outputData: any | null): any {
    if (!outputData) {
      outputData = {
        'Domain Name': '',
        'Creation Date': '',
        'Updated Date': '',
        'Registry Expiry Date': '',
        'Domain Status': [],
        'Registrar': '',
      }
    }

    outputData = WhoIsParser.iterParse(rawData, outputData)

    return outputData
  }
}
export declare function tcpWhois(domain: string, queryOptions: string, server: string, port: number, encoding: string, proxy: ProxyData | null): Promise<string>;
export declare function whois(domain: string, parse, options: WhoIsOptions | null): Promise<WhoIsResponse>;
export declare function lookup(domain: string, options: WhoIsOptions | null): Promise<WhoIsResponse>;
export declare function batchWhois(domains: string[], parallel, threads, parse, options: WhoIsOptions | null): Promise<WhoIsResponse[]>;

export { SocksClient } from 'socks'

export * from './constants'
export * from './types'