import { describe, expect, it } from "vitest";
import {
  DISPO_INTERNAL_PROJECT_BUCKETS,
  DISPO_REQUIRED_ROLE_SEEDS,
  createWeekdayAvailabilityFromFte,
  normalizeDispoChapterToken,
  normalizeDispoRoleToken,
  normalizeDispoUtilizationToken,
  resolveCanonicalResourceIdentity,
} from "../index.js";

describe("dispo import normalization", () => {
  it("normalizes canonical identity and detects enterprise/eid conflicts", () => {
    expect(resolveCanonicalResourceIdentity(" Alice.Example ", "alice.example")).toEqual({
      canonicalId: "alice.example",
      normalizedEnterpriseId: "alice.example",
      normalizedEid: "alice.example",
      conflict: false,
    });

    expect(resolveCanonicalResourceIdentity("alice.example", "bob.example")).toEqual({
      canonicalId: null,
      normalizedEnterpriseId: "alice.example",
      normalizedEid: "bob.example",
      conflict: true,
    });
  });

  it("maps chapter, role, and utilization tokens to canonical values", () => {
    expect(normalizeDispoChapterToken("3d")).toBe("Digital Content Production");
    expect(normalizeDispoRoleToken(" pm ")).toBe("Project Manager");
    expect(normalizeDispoUtilizationToken("md")).toBe("MD&I");
    expect(normalizeDispoUtilizationToken("un")).toBeNull();
    expect(normalizeDispoRoleToken("unknown")).toBeNull();
  });

  it("creates the default weekday fallback availability from fte", () => {
    expect(createWeekdayAvailabilityFromFte(1)).toEqual({
      monday: 8,
      tuesday: 8,
      wednesday: 8,
      thursday: 8,
      friday: 8,
    });

    expect(createWeekdayAvailabilityFromFte(0.5)).toEqual({
      monday: 4,
      tuesday: 4,
      wednesday: 4,
      thursday: 4,
      friday: 4,
    });

    expect(createWeekdayAvailabilityFromFte(0.8)).toEqual({
      monday: 6.4,
      tuesday: 6.4,
      wednesday: 6.4,
      thursday: 6.4,
      friday: 6.4,
    });
  });

  it("keeps canonical bucket and role seed definitions stable", () => {
    expect(DISPO_INTERNAL_PROJECT_BUCKETS).toEqual([
      {
        sourceToken: "MO",
        shortCode: "INT-MO",
        name: "Management & Operations",
        utilizationCategoryCode: "M&O",
      },
      {
        sourceToken: "MD",
        shortCode: "INT-MD",
        name: "Market Development & Initiatives",
        utilizationCategoryCode: "MD&I",
      },
      {
        sourceToken: "PD",
        shortCode: "INT-PD",
        name: "People Development & Recruitment",
        utilizationCategoryCode: "PD&R",
      },
    ]);

    expect(DISPO_REQUIRED_ROLE_SEEDS.map((role) => role.name)).toEqual([
      "2D Artist",
      "3D Artist",
      "Project Manager",
      "Art Director",
    ]);
  });
});
