import { describe, expect, it } from "vitest";
import { inferLicitationBundleDocumentKind, rankLicitationDocumentsForBundle } from "@/lib/licitations/documents";

describe("licitation document bundle ranking", () => {
  it("classifies common naming patterns for Bases/Convocatoria/Anexos", () => {
    expect(
      inferLicitationBundleDocumentKind({
        name: "Bases de Licitacion 2026",
        type: "application/pdf",
        url: "https://example.com/bases.pdf",
      }),
    ).toBe("BASES_LICITACION");

    expect(
      inferLicitationBundleDocumentKind({
        name: "Convocatoria publica",
        type: "application/pdf",
        url: "https://example.com/convocatoria.pdf",
      }),
    ).toBe("CONVOCATORIA");

    expect(
      inferLicitationBundleDocumentKind({
        name: "Anexo tecnico 1",
        type: "application/pdf",
        url: "https://example.com/anexo.pdf",
      }),
    ).toBe("ANEXOS");
  });

  it("returns best candidate per bundle kind", () => {
    const ranked = rankLicitationDocumentsForBundle([
      { name: "Bases de Licitacion", type: "application/pdf", url: "https://example.com/bases.pdf" },
      { name: "Convocatoria", type: "application/pdf", url: "https://example.com/convocatoria.pdf" },
      { name: "Anexo Tecnico", type: "application/pdf", url: "https://example.com/anexo.pdf" },
      { name: "Acta de fallo", type: "application/pdf", url: "https://example.com/fallo.pdf" },
    ]);

    expect(ranked.bases[0]?.url).toContain("bases.pdf");
    expect(ranked.convocatoria[0]?.url).toContain("convocatoria.pdf");
    expect(ranked.anexos[0]?.url).toContain("anexo.pdf");
  });
});
