import { SiteverifyCaptchaProvider, type SiteverifyProviderOptions } from "./siteverify.ts";

export class TurnstileCaptchaProvider extends SiteverifyCaptchaProvider {
  constructor(options: SiteverifyProviderOptions) {
    super(
      {
        name: "turnstile",
        endpoint: "https://challenges.cloudflare.com/turnstile/v0/siteverify",
        client: {
          responseField: "cf-turnstile-response",
          scriptUrl: "https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit",
          widgetClass: "cf-turnstile",
        },
        scoreDirection: "higher-is-human",
      },
      options,
    );
  }
}

export function turnstileProvider(options: SiteverifyProviderOptions): TurnstileCaptchaProvider {
  return new TurnstileCaptchaProvider(options);
}
