import { describe, expect, it } from "vitest";
import type { Node } from "@xyflow/react";
import type { EntropykNodeData } from "./configBuilder";
import { classifyFluidName, mediaForEdge, mediaForPort } from "./mediaStyle";

function node(
  type: string,
  name: string,
  params: Record<string, number | string | boolean> = {},
): Node<EntropykNodeData> {
  return {
    id: name,
    type: "entropykNode",
    position: { x: 0, y: 0 },
    data: { type, name, circuit: 0, rotation: 0, params },
  };
}

describe("mediaStyle", () => {
  it("classifies fluid names", () => {
    expect(classifyFluidName("R134a")).toBe("refrigerant");
    expect(classifyFluidName("Water")).toBe("water");
    expect(classifyFluidName("MEG")).toBe("water");
    expect(classifyFluidName("Air")).toBe("air");
  });

  it("marks brine source ports as water and compressor as refrigerant", () => {
    expect(mediaForPort(node("BrineSource", "evap_water_in"), "outlet")).toBe("water");
    expect(mediaForPort(node("IsentropicCompressor", "comp"), "outlet")).toBe("refrigerant");
    expect(mediaForPort(node("AirSource", "oa"), "outlet")).toBe("air");
  });

  it("marks flooded secondary ports as water and fin-coil secondary as air", () => {
    expect(
      mediaForPort(node("FloodedEvaporator", "evap"), "secondary_inlet"),
    ).toBe("water");
    expect(
      mediaForPort(node("FinCoilCondenser", "cond"), "secondary_inlet"),
    ).toBe("air");
    expect(mediaForPort(node("FinCoilCondenser", "cond"), "inlet")).toBe("refrigerant");
  });

  it("colours an edge from brine source to flooded secondary as water", () => {
    const src = node("BrineSource", "evap_water_in");
    const tgt = node("FloodedEvaporator", "evap");
    expect(mediaForEdge(src, "outlet", tgt, "secondary_inlet")).toBe("water");
  });
});
