import { createHash, randomBytes } from "node:crypto";

const TOKEN_PREFIX = "ndcag";
const ONTOLOGY_TOKEN_PREFIX = "ndcao";
const SETUP_CODE_PREFIX = "ndcsetup";

export function generateAgentToken(): string {
  return `${TOKEN_PREFIX}_${randomBytes(32).toString("base64url")}`;
}

export function generateOntologyAgentToken(): string {
  return `${ONTOLOGY_TOKEN_PREFIX}_${randomBytes(32).toString("base64url")}`;
}

export function hashAgentToken(token: string): string {
  return createHash("sha256").update(token).digest("hex");
}

export function generateAgentSetupCode(): string {
  return `${SETUP_CODE_PREFIX}_${randomBytes(32).toString("base64url")}`;
}

export function hashAgentSetupCode(code: string): string {
  return createHash("sha256").update(code).digest("hex");
}
