import type { CaptchaChallengeGenerator } from "../types.ts";
import {
  alphaCaptchaGenerator,
  alphanumericCaptchaGenerator,
  numberCaptchaGenerator,
} from "./text.ts";
import { calculationCaptchaGenerator } from "./calculation.ts";
import { imageCaptchaGenerator } from "./image.ts";
import {
  honeypotCaptchaGenerator,
  notRobotCaptchaGenerator,
  timingCaptchaGenerator,
} from "./invisible.ts";

export * from "./text.ts";
export * from "./calculation.ts";
export * from "./image.ts";
export * from "./invisible.ts";
export * from "./png.ts";
export * from "./styles.ts";

export function defineCaptchaGenerator<T extends CaptchaChallengeGenerator>(generator: T): T {
  if (!generator.type) throw new TypeError("CAPTCHA generator requires a stable type");
  if (typeof generator.generate !== "function")
    throw new TypeError("CAPTCHA generator requires generate()");
  return generator;
}

export function defaultCaptchaGenerators(): CaptchaChallengeGenerator[] {
  return [
    numberCaptchaGenerator,
    alphaCaptchaGenerator,
    alphanumericCaptchaGenerator,
    calculationCaptchaGenerator,
    imageCaptchaGenerator,
    honeypotCaptchaGenerator,
    timingCaptchaGenerator,
    notRobotCaptchaGenerator,
  ];
}
