import { describe, expect, it } from "vitest";
import {
  getHanmacFamilyTenantOrderRank,
  orderHanmacFamilyChildren,
  orderHanmacFamilyTenants,
} from "./hanmacFamilyOrder";

function tenant(name: string, slug: string) {
  return { name, slug };
}

describe("hanmac family organization order", () => {
  it("orders the top hanmac-family siblings by policy", () => {
    const ordered = orderHanmacFamilyTenants([
      tenant("바론그룹", "baron-group"),
      tenant("한맥기술", "hanmac"),
      tenant("삼안", "saman"),
      tenant("총괄기획&기술개발센터", "gpdtdc"),
    ]);

    expect(ordered.map((item) => item.name)).toEqual([
      "총괄기획&기술개발센터",
      "삼안",
      "한맥기술",
      "바론그룹",
    ]);
  });

  it("keeps hanmac-family as the root before ordered descendants", () => {
    const family = tenant("한맥가족", "hanmac-family");
    const children = orderHanmacFamilyChildren(family, [
      tenant("바론그룹", "baron-group"),
      tenant("총괄기획&기술개발센터", "gpdtdc"),
      tenant("삼안", "saman"),
      tenant("한맥기술", "hanmac"),
    ]);

    expect([family, ...children].map((item) => item.name)).toEqual([
      "한맥가족",
      "총괄기획&기술개발센터",
      "삼안",
      "한맥기술",
      "바론그룹",
    ]);
  });

  it("does not rank generic technical centers as GPDTDC", () => {
    expect(
      getHanmacFamilyTenantOrderRank(tenant("기술개발센터", "rnd-center")),
    ).toBe(Number.MAX_SAFE_INTEGER);
  });
});
