import type { CaptchaEngine, CaptchaStore } from "@wrnexus/captcha/server";

export interface ManagedCaptchaProject {
  id: string;
  name: string;
  siteKey: string;
  secretHash: string;
  engineSecret: string;
  allowedHostnames: string[];
  monthlyQuota: number;
  usageMonth: string;
  usageCount: number;
  enabled: boolean;
  createdAt: number;
  updatedAt: number;
}

export interface PublicProjectKey {
  id: string;
  name: string;
  siteKey: string;
  secretKey: string;
  allowedHostnames: string[];
  monthlyQuota: number;
}

export interface ManagedProjectStore {
  create(project: ManagedCaptchaProject): Promise<void>;
  update(project: ManagedCaptchaProject): Promise<void>;
  getById(id: string): Promise<ManagedCaptchaProject | undefined>;
  getBySiteKey(siteKey: string): Promise<ManagedCaptchaProject | undefined>;
  getBySecretHash(secretHash: string): Promise<ManagedCaptchaProject | undefined>;
  list(): Promise<ManagedCaptchaProject[]>;
}

export interface ManagedCaptchaServiceOptions {
  adminToken: string;
  projectStore?: ManagedProjectStore;
  captchaStore?: CaptchaStore;
  baseUrl?: string;
  defaultMonthlyQuota?: number;
  now?: () => number;
  randomBytes?: (length: number) => Uint8Array;
  engineFactory?: (project: ManagedCaptchaProject) => CaptchaEngine;
}
