import type { RegexFlavourId } from "../model/flavour";
import type { RegexSyntaxProvider } from "./SyntaxProvider";
import { COMMUNITY_SYNTAX_PROVIDERS } from "./providers/community/CommunitySyntaxProvider";
import { EcmaScriptSyntaxProvider } from "./providers/ecmascript/EcmaScriptSyntaxProvider";
import { JavaSyntaxProvider } from "./providers/java/JavaSyntaxProvider";
import { Pcre2SyntaxProvider } from "./providers/pcre2/Pcre2SyntaxProvider";
import { PythonSyntaxProvider } from "./providers/python/PythonSyntaxProvider";

export const SYNTAX_PROVIDERS: Readonly<
  Partial<Record<RegexFlavourId, RegexSyntaxProvider>>
> = {
  ecmascript: new EcmaScriptSyntaxProvider(),
  pcre2: new Pcre2SyntaxProvider(),
  python: new PythonSyntaxProvider(),
  java: new JavaSyntaxProvider(),
  ...COMMUNITY_SYNTAX_PROVIDERS,
};

export function requireSyntaxProvider(
  flavour: RegexFlavourId,
): RegexSyntaxProvider {
  const provider = SYNTAX_PROVIDERS[flavour];
  if (provider) return provider;
  throw new Error(`No syntax provider is registered for ${flavour}.`);
}
