import { parseApplyLayerStylePayload } from "./toolCallStyleHelpers";

describe("parseApplyLayerStylePayload", () => {
  it("accepts a valid snake_case interval contract", () => {
    expect(
      parseApplyLayerStylePayload({
        layer_id: "pipes",
        style_config: {
          property: "velocity",
          classification_method: "custom_breaks",
          segments: 3,
          custom_breaks: [0, 1, 2, 3],
          color_type: "custom",
          custom_colors: ["#000000", "#777777", "#ffffff"],
        },
      }),
    ).toMatchObject({
      layerId: "pipes",
      resetToDefault: false,
      styleConfig: { segments: 3, customBreaks: [0, 1, 2, 3] },
    });
  });

  it("rejects invalid class counts and array cardinalities", () => {
    expect(
      parseApplyLayerStylePayload({
        layer_id: "pipes",
        style_config: { segments: 1, property: "velocity" },
      }),
    ).toBeNull();
    expect(
      parseApplyLayerStylePayload({
        layer_id: "junctions",
        style_config: {
          segments: 3,
          custom_breaks: [0, 1, 2],
        },
      }),
    ).toBeNull();
  });

  it("keeps camelCase compatibility", () => {
    expect(
      parseApplyLayerStylePayload({
        layerId: "junctions",
        styleConfig: { opacity: 0.5, colorType: "gradient" },
      }),
    ).toMatchObject({ layerId: "junctions", styleConfig: { opacity: 0.5 } });
  });
});
