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

import {
  extractMatriculeMarker,
  normalizeMatricule,
  parsePayslipFileName,
} from "../../src/services/fiches-paie.service";

describe("fiches-paie.service", () => {
  it("accepte uniquement le format strict des fichiers de paie", () => {
    expect(parsePayslipFileName("2026_01-Paies ENVIE 2E.pdf")).toEqual({
      year: 2026,
      month: 1,
      label: "ENVIE 2E",
    });
    expect(parsePayslipFileName("2026_13-Paies ENVIE 2E.pdf")).toBeNull();
    expect(parsePayslipFileName("paies-2026-01.pdf")).toBeNull();
    expect(parsePayslipFileName("2026_01-Paies.pdf")).toBeNull();
  });

  it("détecte le matricule malgré les espaces autour des deux-points", () => {
    expect(extractMatriculeMarker("Bulletin Matricule : 001234 Emploi")).toEqual(
      {
        hasMarker: true,
        matricule: "1234",
      },
    );
  });

  it("considère un libellé sans numéro comme une frontière de fiche", () => {
    expect(extractMatriculeMarker("Matricule : Emploi")).toEqual({
      hasMarker: true,
      matricule: null,
    });
  });

  it("normalise les zéros initiaux sans confondre COS et Matricule", () => {
    expect(normalizeMatricule("00042")).toBe("42");
    expect(normalizeMatricule(42)).toBe("42");
    expect(normalizeMatricule("COS-42")).toBeNull();
  });
});
