import type { CheckerDefinition } from "./types";

export class CheckerRegistry {
  get definitions(): CheckerDefinition[] {
    return [...this.checkers.values()];
  }

  get supportedTypes(): string[] {
    return [...this.checkers.keys()];
  }

  private checkers = new Map<string, CheckerDefinition>();

  get(type: string): CheckerDefinition {
    const checker = this.checkers.get(type);
    if (!checker) {
      throw new Error(`不支持的 probe type: "${type}"`);
    }
    return checker;
  }

  register(checker: CheckerDefinition): void {
    if (this.checkers.has(checker.type)) {
      throw new Error(`Checker type "${checker.type}" 已注册`);
    }
    this.checkers.set(checker.type, checker);
  }

  tryGet(type: string): CheckerDefinition | undefined {
    return this.checkers.get(type);
  }
}
