/**
 * Parser utilities for protocol detection
 * Now delegates to protocol modules for actual parsing
 */

import type { THttpMethod, TTlsVersion } from '../models/detection-types.js';
import { HttpParser, HTTP_METHODS, HTTP_VERSIONS } from '../../protocols/http/index.js';
import { tlsVersionToString as protocolTlsVersionToString } from '../../protocols/tls/index.js';

// Re-export constants for backward compatibility
export { HTTP_METHODS, HTTP_VERSIONS };

/**
 * Parse HTTP request line
 */
export function parseHttpRequestLine(line: string): {
  method: THttpMethod;
  path: string;
  version: string;
} | null {
  // Delegate to protocol parser
  const result = HttpParser.parseRequestLine(line);
  return result ? {
    method: result.method as THttpMethod,
    path: result.path,
    version: result.version
  } : null;
}

/**
 * Parse HTTP header line
 */
export function parseHttpHeader(line: string): { name: string; value: string } | null {
  // Delegate to protocol parser
  return HttpParser.parseHeaderLine(line);
}

/**
 * Parse HTTP headers from lines
 */
export function parseHttpHeaders(lines: string[]): Record<string, string> {
  // Delegate to protocol parser
  return HttpParser.parseHeaders(lines);
}

/**
 * Convert TLS version bytes to version string
 */
export function tlsVersionToString(major: number, minor: number): TTlsVersion | null {
  // Delegate to protocol parser
  return protocolTlsVersionToString(major, minor) as TTlsVersion;
}

/**
 * Extract domain from Host header value
 */
export function extractDomainFromHost(hostHeader: string): string {
  // Delegate to protocol parser
  return HttpParser.extractDomainFromHost(hostHeader);
}

/**
 * Validate domain name
 */
export function isValidDomain(domain: string): boolean {
  // Delegate to protocol parser
  return HttpParser.isValidDomain(domain);
}

/**
 * Check if string is a valid HTTP method
 */
export function isHttpMethod(str: string): str is THttpMethod {
  // Delegate to protocol parser
  return HttpParser.isHttpMethod(str) && (str as THttpMethod) !== undefined;
}

