import { describe, it, expect } from "vitest";

describe("voiceprint ML engine", () => {
  describe("preprocessAudio", () => {
    it("returns default audio features", async () => {
      const { preprocessAudio } = await import("./ml.engine");
      const buffer = Buffer.from("fake-audio-data");
      const result = await preprocessAudio(buffer);
      expect(result.duration).toBe(0);
      expect(result.sampleRate).toBe(16000);
      expect(result.channels).toBe(1);
      expect(result.rawPcm).toEqual(buffer);
    });
  });

  describe("detectSynthetic", () => {
    it("returns default detection result", async () => {
      const { detectSynthetic } = await import("./ml.engine");
      const features = { duration: 0, sampleRate: 16000, channels: 1, rawPcm: Buffer.from("test") };
      const result = await detectSynthetic(features);
      expect(result.isSynthetic).toBe(false);
      expect(result.confidence).toBe(1.0);
      expect(result.score).toBe(0.0);
    });
  });

  describe("matchVoice", () => {
    it("returns default match result", async () => {
      const { matchVoice } = await import("./ml.engine");
      const embedding = { vector: new Float64Array(256), hash: "test-hash" };
      const result = await matchVoice(embedding, "enrollment-1");
      expect(result.similarity).toBe(0);
      expect(result.matched).toBe(false);
    });
  });

  describe("generateEmbedding", () => {
    it("returns an embedding with hash from the audio buffer", async () => {
      const { generateEmbedding } = await import("./ml.engine");
      const features = { duration: 1, sampleRate: 16000, channels: 1, rawPcm: Buffer.from("test-audio") };
      const result = await generateEmbedding(features);
      expect(result.vector.length).toBe(256);
      expect(result.hash).toBeTruthy();
      expect(typeof result.hash).toBe("string");
    });
  });
});
